centos6.8配置防火墻
1, 首先去/etc/sysconfig目錄查看iptables文件有沒(méi)有
[root@iZj6c7eeosj2t5vjw8rf4xZ bin]# cd /etc/sysconfig/
[root@iZj6c7eeosj2t5vjw8rf4xZ sysconfig]# ls -l
total 136
-rw-r--r-- 1 root root 403 Mar 22 2017 atd
-rw-r----- 1 root root 992 Mar 22 2017 auditd
-rw-r--r--. 1 root root 397 Jul 10 12:26 authconfig
drwxr-xr-x. 2 root root 4096 Jul 10 12:25 cbq
-rw-r--r-- 1 root root 41 Oct 15 21:10 clock
drwxr-xr-x. 2 root root 4096 Oct 4 10:24 console
-rw-r--r--. 1 root root 16 Jul 10 12:26 firstboot
-rw-r--r--. 1 root root 25 Jul 10 12:26 grub
-rw-r--r-- 1 root root 529 Jul 26 17:16 htcacheclean
-rw-r--r-- 1 root root 947 Jul 26 17:16 httpd
-rw-r--r--. 1 root root 43 Oct 15 21:10 i18n
-rw-r--r-- 1 root root 1154 Oct 4 10:24 init
-rw-------. 1 root root 1988 Jul 24 2015 ip6tables-config
-rw-------. 1 root root 1974 Jul 24 2015 iptables-config
-rw-r--r-- 1 root root 903 Feb 2 2016 irqbalance
-rw-r--r-- 1 root root 180 Oct 16 15:51 kernel
-rw-r--r--. 1 root root 63 Jul 10 12:26 keyboard
drwxr-xr-x. 2 root root 4096 Oct 4 10:24 modules
-rw-r--r-- 1 root root 634 Oct 4 10:24 netconsole
-rw-r--r-- 1 root root 78 Oct 15 21:10 network
drwxr-xr-x. 4 root root 4096 Oct 4 10:24 networking
drwxr-xr-x. 2 root root 4096 Oct 16 15:51 network-scripts
-rw-r--r-- 1 root root 85 Jan 11 2017 ntpd
-rw-r--r-- 1 root root 167 Jan 11 2017 ntpdate
-rw-r--r-- 1 root root 43 Jul 6 14:11 php-fpm
-rw-r--r-- 1 root root 2585 Jan 26 2017 raid-check
-rw-r--r-- 1 root root 659 Oct 4 10:24 readonly-root
-rw-r--r--. 1 root root 200 Dec 10 2014 rsyslog
-rw-r--r-- 1 root root 210 Nov 18 2016 sandbox
-rw-r--r--. 1 root root 553 Feb 27 2015 saslauthd
lrwxrwxrwx. 1 root root 17 Jul 10 12:25 selinux -> ../selinux/config
-rw-r----- 1 root root 438 Sep 1 01:36 sshd
-rw-------. 1 root root 60 Jul 10 12:26 system-config-firewall
-rw-------. 1 root root 68 Jul 10 12:26 system-config-firewall.old
-rw-r--r-- 1 root root 183 Sep 6 2016 udev
如果沒(méi)有就按下面的步驟
- 任意運(yùn)行一條iptables防火墻規(guī)則配置命令:
iptables -P OUTPUT ACCEPT
- 對(duì)iptables服務(wù)進(jìn)行保存:
service iptables save
- 重啟iptables服務(wù):
service iptables restart
[root@iZj6c7eeosj2t5vjw8rf4xZ sysconfig]# iptables -P OUTPUT ACCEPT
[root@iZj6c7eeosj2t5vjw8rf4xZ sysconfig]# service iptables save
iptables: Saving firewall rules to /etc/sysconfig/iptables:[ OK ]
[root@iZj6c7eeosj2t5vjw8rf4xZ sysconfig]# service iptables restart
iptables: Setting chains to policy ACCEPT: filter [ OK ]
iptables: Flushing firewall rules: [ OK ]
iptables: Unloading modules: [ OK ]
iptables: Applying firewall rules: [ OK ]
然后再次查看/etc/sysconfig目錄,就發(fā)現(xiàn)iptables存在了
[root@iZj6c7eeosj2t5vjw8rf4xZ sysconfig]# ls -l
total 140
-rw-r--r-- 1 root root 403 Mar 22 2017 atd
-rw-r----- 1 root root 992 Mar 22 2017 auditd
-rw-r--r--. 1 root root 397 Jul 10 12:26 authconfig
drwxr-xr-x. 2 root root 4096 Jul 10 12:25 cbq
-rw-r--r-- 1 root root 41 Oct 15 21:10 clock
drwxr-xr-x. 2 root root 4096 Oct 4 10:24 console
-rw-r--r--. 1 root root 16 Jul 10 12:26 firstboot
-rw-r--r--. 1 root root 25 Jul 10 12:26 grub
-rw-r--r-- 1 root root 529 Jul 26 17:16 htcacheclean
-rw-r--r-- 1 root root 947 Jul 26 17:16 httpd
-rw-r--r--. 1 root root 43 Oct 15 21:10 i18n
-rw-r--r-- 1 root root 1154 Oct 4 10:24 init
-rw-------. 1 root root 1988 Jul 24 2015 ip6tables-config
-rw------- 1 root root 190 Oct 17 14:29 iptables
-rw-------. 1 root root 1974 Jul 24 2015 iptables-config
-rw-r--r-- 1 root root 903 Feb 2 2016 irqbalance
-rw-r--r-- 1 root root 180 Oct 16 15:51 kernel
-rw-r--r--. 1 root root 63 Jul 10 12:26 keyboard
drwxr-xr-x. 2 root root 4096 Oct 4 10:24 modules
-rw-r--r-- 1 root root 634 Oct 4 10:24 netconsole
-rw-r--r-- 1 root root 78 Oct 15 21:10 network
drwxr-xr-x. 4 root root 4096 Oct 4 10:24 networking
drwxr-xr-x. 2 root root 4096 Oct 16 15:51 network-scripts
-rw-r--r-- 1 root root 85 Jan 11 2017 ntpd
-rw-r--r-- 1 root root 167 Jan 11 2017 ntpdate
-rw-r--r-- 1 root root 43 Jul 6 14:11 php-fpm
-rw-r--r-- 1 root root 2585 Jan 26 2017 raid-check
-rw-r--r-- 1 root root 659 Oct 4 10:24 readonly-root
-rw-r--r--. 1 root root 200 Dec 10 2014 rsyslog
-rw-r--r-- 1 root root 210 Nov 18 2016 sandbox
-rw-r--r--. 1 root root 553 Feb 27 2015 saslauthd
lrwxrwxrwx. 1 root root 17 Jul 10 12:25 selinux -> ../selinux/config
-rw-r----- 1 root root 438 Sep 1 01:36 sshd
-rw-------. 1 root root 60 Jul 10 12:26 system-config-firewall
-rw-------. 1 root root 68 Jul 10 12:26 system-config-firewall.old
-rw-r--r-- 1 root root 183 Sep 6 2016 udev
2,我們可以通過(guò)兩種方式修改端口,直接編輯iptables 文件輸入以下內(nèi)容即可開(kāi)放80端口
-A INPUT -m state --state NEW -m tcp -p tcp --dport 8080 -j ACCEPT
或者使用命令模式
[root@iZj6c7eeosj2t5vjw8rf4xZ sysconfig]# iptables -I INPUT -p tcp --dport 8080 -j ACCEPT
[root@iZj6c7eeosj2t5vjw8rf4xZ sysconfig]# service iptables save
iptables: Saving firewall rules to /etc/sysconfig/iptables:[ OK ]
[root@iZj6c7eeosj2t5vjw8rf4xZ sysconfig]# service iptables restart
iptables: Setting chains to policy ACCEPT: filter [ OK ]
iptables: Flushing firewall rules: [ OK ]
iptables: Unloading modules: [ OK ]
iptables: Applying firewall rules: [ OK ]
兩種形式不同的地方是命令的話們需要service iptables save而文件的形式不需要。
最后都要執(zhí)行service iptables restart命令。