CentOS 7 下 安裝Webmin 啓動防火牆失敗----Applying firewall rules:iptables-restore:line 2 failed

  最近學習CentOS 7 系統管理,使用的是《CentOS 6.X系統管理實戰寶典》一書------由於網購的CentOS 7 的書尚未送到 O(‘  ’!!)O~html

(1)先使用yum方法安裝Webmin:web

  默認使用yum時沒法安裝Webmin,緣由是該軟件沒有在官方站點存放。雖然之前要用tar方式安裝,可是以後編譯出了RPM安裝包,因此只好自行配置更新站點。在/etc/yum.repo.d中建立webmin.repo文件,編輯完成後保存退出,而後導入Webmin開放源代碼的GPG的數字簽名:centos

 

[root@localhost /]# vi /etc/yum.repos.d/webmin.repo
[Webmin]
name=Webmin Distribution Neutral
baseurl=http://download.webmin.com/download/yum    //配置webmin安裝來源站點
enabled=1
[root@localhost /]# rpm --import http://www.webmin.com/jcameron-key.asc

 

 

 

而後使用yum方式進行安裝,瀏覽器

 

[root@localhost /]# yum install webmin

 

 

(2)安裝Apache軟件:服務器

[root@localhost ~]# yum install httpd -y

 

 

(3)想要安裝Webmin系統管理工具,須要從新配置防火牆,Webmin默認使用的端口爲10000,按照書上的教程設置了 /etc/sysconfig/iptables文件:app

[root@localhost /]# vi /etc/sysconfig/iptables
#Firewall configuration written by system-config-firewall
#Manual customization of this file is not recommanded.
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
-A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
-A INPUT -p icmp -j ACCEPT
-A INPUT -i lo -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT
-A INPUT -m state --state NEW -m udp -p tcp --dport 10000 -j ACCEPT
-A INPUT -j REJECT --reject-with icmp-host-prohibited
-A FORWARD -j REJECT --reject-with icmp-host-prohibited
COMMIT

按照書上的教程執行 service iptables restart 命令,卻失敗了,覺得是CentOS 6.X的命令和 CentOS 7 的命令不兼容的問題,網上搜CentOS 7啓動防火牆的方法,找到這個網頁:tcp

CentOS7下Firewall防火牆配置用法詳解 

按照以下圖所示區域的Instruction,進行配置:工具

----------------------------------------如下爲圖片---------------------------------------------學習

-----------------------------------------以上爲圖片----------------------------------------------網站

(i) yum install iptables-services ,沒有問題

(ii) systemctl mask firewalld.service ,沒有問題

(iii) systemctl enable iptables.servie , 沒問題

爲了提升網速,我禁用了ipv6,因此沒有執行 systemctl start ip6tables.service

(iv) systemctl stop firewalld.service , 沒問題

(v) systemctl start iptables.service ------ 有問題!

  如圖:

 

使用 cat /var/log/messages | grep iptables 命令查看相關錯誤:

Applying firewall rules: iptables-restore:line 2 failed 得知是 iptables 文件的第二行由錯,因而 cat /etc/sysconfig/iptables:

一看,原來是 Manual configuration of this file is not recommended. 那句話沒有在前面加上#號註釋掉!

遂註釋之~

再次 systemctl start iptables.service,結果:

說是upd match: only valid for protocol 17

最終從這個網頁獲得提示:http://stackoverflow.com/questions/25144598/failed-to-apply-firewall-rules-with-iptables-restore

輸入 iptables-restore < /etc/sysconfig/iptables:

顯示第14行有問題,但跟那個StackFlow網站的朋友的問題同樣,個人第14行是 COMMIT:

而他修改的方式是把 -p udp -m tcp 改成 -p udp -m udp, 而我檢查我按照書上的Instruction寫的iptables,也有這麼一行 -m udp -p tcp ,應該是不匹配的問題。想到Webmin要用瀏覽器管理服務器,用的應該是tcp協議,因而將之改成 -m tcp -p tcp:

再輸入 systemctl start iptables.service, 沒問題。

輸入 service httpd restart 命令重啓 Apache 服務器, 瀏覽器登陸Webmin管理器:

能夠看到登陸界面了,說明iptables配置成功!

相關文章
相關標籤/搜索