這篇文章是針對2020年下載安裝的kali系統碰到的關于 iptables開放22端口失敗等一系列問題的解決辦法,如果是其它系統,可以借鑒一下思路。
各種報錯:
# sudo systemctl start iptables
Failed to start iptables.service: Unit iptables.service not found.
# sudo systemctl enable iptables
Failed to enable unit: Unit file iptables.service does not exist.
# sudo service iptables start
Failed to start iptables.service: Unit iptables.service not found.
# sudo service iptables enable
iptables: unrecognized service
0
1
2
3
4
5
6
7
8
9
10
# sudo systemctl start iptables
Failedtostartiptables.service:Unitiptables.servicenotfound.
# sudo systemctl enable iptables
Failedtoenableunit:Unitfileiptables.servicedoesnotexist.
# sudo service iptables start
Failedtostartiptables.service:Unitiptables.servicenotfound.
# sudo service iptables enable
iptables:unrecognizedservice
下面的錯誤是怎么出來的我忘了
See systemctl status iptables.service" and "journalctl -xe" for details.
Job for iptables.service failed because the control process exited with error code.
0
1
Seesystemctlstatusiptables.service" and "journalctl-xe"fordetails.
Jobforiptables.servicefailedbecausethecontrolprocessexitedwitherrorcode.
主要思想就是想盡量少的安裝其它不必要的命令,所以折騰了好一陣子。
開機啟動默認會執行/etc/init.d/ 下的所有可執行文件,
所以,粗暴點,就在這個文件夾(/etc/init.d/)下加個我自己的可執行文件吧,寫好shell語言,也方便我以后再折騰。
步驟:
1、創建文件
$ sudo vim /etc/init.d/mrdede.init
文件內容:
#!/bin/sh
### BEGIN INIT INFO
# Default-Start:???? 2 3 4 5
# Default-Stop:????? 0 1 6
### END INIT INFO
# mrdede Custom File
# iptables 開放 22 端口
iptables -A INPUT -p tcp --dport 22 -j ACCEPT
# 開啟 SSH 服務
service sshd start
if [ $? -ne 0 ]
then
service ssh start
fi
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#!/bin/sh
### BEGIN INIT INFO
# Default-Start:???? 2 3 4 5
# Default-Stop:????? 0 1 6
### END INIT INFO
# mrdede Custom File
# iptables 開放 22 端口
iptables-AINPUT-ptcp--dport22-jACCEPT
# 開啟 SSH 服務
servicesshdstart
if[$?-ne0]
then
servicesshstart
fi
2、完成后保存 :wq + 回車
3、文件設置來可執行文件
$ sudo chmod +x /etc/init.d/mrdede.init
0
$sudochmod+x/etc/init.d/mrdede.init
4、重啟主機
$ sudo reboot
5、驗證是否成功。
1)先查看iptable新添加的端口是否存在
$ sudo iptables –list
2)再看service中是的ssh是否啟動
$ sudo service –status-all
顯示出來的是所有服務,前面帶有 [ + ] 表示已啟動,[ - ] 表示已關閉
找到ssh ,正常的話應該是已啟動,之后還可以看到之前加入到服務器的mrdede.init 文件。
6、完成。
多種原因可以造成同一種問題的表現,所以如果這篇文章沒有解決你的問題,可以參考其它文章繼續你的折騰。