LoginSignup
2
0

More than 1 year has passed since last update.

firewallでエラー発生

Last updated at Posted at 2021-09-05

ubuntuからrails sでhttp://127.0.0.1:3000で接続できない問題を解決する話の記事

$ sudo ufw status
[sudo] password for [user_name]:
Status: inactive

inactiveになってる。
(Ubuntu Serverのデフォルトではファイアーウォールは無効になっているらしい。)

3000番ポートを開けたい場合には sudo ufw allow 3000

$ sudo ufw allow 3000
Rules updated
Rules updated (v6)
$ sudo ufw reload
Firewall not enabled (skipping reload)

3000開けれたかもしれんが、ファイアウォールが有効になってない。

ファイアーウォールを有効にする。

sudo ufw enable
ERROR: problem running ufw-init
iptables-restore v1.8.4 (legacy): Couldn't load match `limit':No such file or directory

Error occurred at line: 63
Try `iptables-restore -h' or 'iptables-restore --help' for more information.
iptables-restore v1.8.4 (legacy): Couldn't load match `limit':No such file or directory

Error occurred at line: 25
Try `iptables-restore -h' or 'iptables-restore --help' for more information.
ip6tables-restore v1.8.4 (legacy): Couldn't load match `limit':No such file or directory

Error occurred at line: 25
Try `ip6tables-restore -h' or 'ip6tables-restore --help' for more information.

Problem running '/etc/ufw/before.rules'
Problem running '/etc/ufw/user.rules'
Problem running '/etc/ufw/user6.rules'

エラー…

$ systemctl status firewalld.service
System has not been booted with systemd as init system (PID 1). Can't operate.
Failed to connect to bus: Host is down

systemctlが動かない。。
エラーの内容としては、systemdがPID 1(init system)ではないので操作できないよ、という感じ

PID 1が「/init」となっていて「systemd」でない。

$ ps aux
USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root         1  0.0  0.0    900   524 ?        Sl   00:21   0:00 /init
root        99  0.0  0.0    900    80 ?        Ss   00:21   0:00 /init
root       100  0.0  0.0    900    80 ?        S    00:21   0:00 /init
toyoda     101  0.0  0.3 764636 42776 pts/0    Ssl+ 00:21   0:00 docker serve --address unix:///home/toyoda/.docker/run/root       102  0.0  0.0      0     0 ?        Z    00:21   0:00 [init] <defunct>
root       120  0.0  0.0    900    80 ?        S    00:21   0:00 /init
root       121  0.0  0.2 1464380 26796 pts/1   Ssl+ 00:21   0:00 /mnt/wsl/docker-desktop/docker-desktop-proxy --distro-nroot       142  0.0  0.0    900    80 ?        Ss   00:47   0:00 /init
root       143  0.0  0.0    900    80 ?        R    00:47   0:00 /init
toyoda     144  0.1  0.0  10088  4964 pts/2    Ss   00:47   0:00 -bash
toyoda     253  0.0  0.0  10620  3280 pts/2    R+   00:47   0:00 ps aux

これが原因でsystemctlが動いていないよう
エラーメッセージから考えても、PID 1がsystemdになればよい、

上記サイトを参考にインストールする

使うものは、こちらのリポジトリ。
以下のGitHubで公開されている genie を利用することで systemd を PID1 で動作させることができるらしい。
https://github.com/arkane-systems/genie
WSL2限定だが、問題を解決してくれる。

$ sudo apt install git dotnet-runtime-3.1 daemonize
Reading package lists... Done
Building dependency tree
Reading state information... Done
E: Unable to locate package dotnet-runtime-3.1
E: Couldn't find any package by glob 'dotnet-runtime-3.1'
$ git clone https://github.com/arkane-systems/genie.git
Cloning into 'genie'...
remote: Enumerating objects: 2074, done.
remote: Counting objects: 100% (466/466), done.
remote: Compressing objects: 100% (265/265), done.
remote: Total 2074 (delta 265), reused 359 (delta 189), pack-reused 1608
Receiving objects: 100% (2074/2074), 683.54 KiB | 1.22 MiB/s, done.
Resolving deltas: 100% (1085/1085), done.
$ cd genie/
$ ls
LICENSE  Makefile  README.md  binsrc  container-package-arch.sh  container-package-fedora.sh  othersrc  package
$ make install
make: *** No rule to make target 'install'.  Stop.
$ genie -s
genie: command not found

うまくいかない。
dotnet-runtime-3.1 daemonizeのインストールに失敗している。
(後で気づいた)

$ sudo apt install daemonize
$ sudo apt-get install -y gpg
$ wget -O - https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor -o microsoft.asc.gpg
$ sudo mv microsoft.asc.gpg /etc/apt/trusted.gpg.d/
$ wget https://packages.microsoft.com/config/ubuntu/20.04/prod.list
$ sudo mv prod.list /etc/apt/sources.list.d/microsoft-prod.list
$ sudo chown root:root /etc/apt/trusted.gpg.d/microsoft.asc.gpg
$ sudo chown root:root /etc/apt/sources.list.d/microsoft-prod.list
$ sudo apt-get update; \
  sudo apt-get install -y apt-transport-https && \
  sudo apt-get update && \
  sudo apt-get install -y dotnet-sdk-3.1
$ curl -s https://packagecloud.io/install/repositories/arkane-systems/wsl-translinux/script.deb.sh | sudo bash
bash: line 1: syntax error near unexpected token `newline'
bash: line 1: `<!DOCTYPE html>'
$ sudo apt install -y systemd-genie
Reading package lists... Done
Building dependency tree
Reading state information... Done
E: Unable to locate package systemd-genie

systemd-genieがインストールできてない。
なんか同じように失敗している人いる
https://teratail.com/questions/335429

curl -s https://packagecloud.io/install/repositories/arkane-systems/wsl-translinux/script.deb.sh -O

上記実行してファイルダウンロードしてみた。
ダウンロードされたscript.deb.shを確認したらシェルではなくhtmlファイルになっている。。

dotnet-runtime-3.1 daemonizeのインストールに失敗していたっぽい。
もう一度やったら今度は成功したかも。

$ sudo apt install git dotnet-runtime-3.1 daemonize
[sudo] password for [user_name]:
Reading package lists... Done
Building dependency tree
Reading state information... Done
daemonize is already the newest version (1.7.8-1).
dotnet-runtime-3.1 is already the newest version (3.1.16-1).
dotnet-runtime-3.1 set to manually installed.
Suggested packages:
  git-daemon-run | git-daemon-sysvinit git-doc git-el git-email git-gui gitk gitweb git-cvs git-mediawiki git-svn
The following packages will be upgraded:
  git
1 upgraded, 0 newly installed, 0 to remove and 109 not upgraded.
Need to get 4557 kB of archives.
After this operation, 0 B of additional disk space will be used.
Do you want to continue? [Y/n] y
Get:1 http://archive.ubuntu.com/ubuntu focal-updates/main amd64 git amd64 1:2.25.1-1ubuntu3.1 [4557 kB]
Fetched 4557 kB in 6s (826 kB/s)
(Reading database ... 48115 files and directories currently installed.)
Preparing to unpack .../git_1%3a2.25.1-1ubuntu3.1_amd64.deb ...
Unpacking git (1:2.25.1-1ubuntu3.1) over (1:2.25.1-1ubuntu3) ...
Setting up git (1:2.25.1-1ubuntu3.1) ...
$ cd genie/
$ make install
make: *** No rule to make target 'install'.  Stop.

make installで以前エラー発生。
https://detail.chiebukuro.yahoo.co.jp/qa/question_detail/q13135991238
https://github.com/arkane-systems/genie/blob/master/othersrc/docs/readme.md

定義されているサービスを全部見るコマンドを実行

$ systemctl list-unit-files --type=service
UNIT FILE                              STATE    VENDOR PRESET
finalrd.service                        enabled  enabled
firewalld.service                      masked   enabled
friendly-recovery.service              static   enabled

firewalld.serviceがmaskedになっている。

systemdを理解しなくてはダメかも

unmaskにしたらいいのかと思ってやったら、systemctl list-unit-files --type=serviceでfirewallが表示されなくなってしまった。。

$ sudo systemctl unmask firewalld.service
Removed /etc/systemd/system/firewalld.service.

maskしたらまた出るようになった。

$ sudo systemctl mask firewalld.service
Created symlink /etc/systemd/system/firewalld.service → /dev/null.

masked は、設定を /dev/null とシンボリックリンクを張ることによって、実行を禁止にした状態。
なぜ、こんなのがあるかというと、実行する設定にしなくても依存関係で実行される場合を防ぐため。
普通は使わないが、バグっていてどうしても起動したくない場合に使う。

systemctl mask hoge.service
で、設定。
systemctl unmask hoge.service
でマスクを解除。

断念かな。。

2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0