在Linux上防火牆開放對應的端口的命令如下:
方式一:
[root@localhost sbin]# /sbin/iptables -I INPUT -p tcp --dport 80 -j ACCEPT [root@localhost sbin]# [root@localhost sbin]# /etc/rc.d/init.d/iptables save iptables: Saving firewall rules to /etc/sysconfig/iptables:[ OK ] [root@localhost sbin]# [root@localhost sbin]# /etc/rc.d/init.d/iptables restart iptables: Setting chains to policy ACCEPT: filter [ OK ] iptables: Flushing firewall rules: [ OK ] iptables: Unloading modules: [ OK ] iptables: Applying firewall rules: [ OK ] [root@localhost sbin]# [root@localhost sbin]# /etc/rc.d/init.d/iptables status Table: filter Chain INPUT (policy ACCEPT) num target prot opt source destination 1 ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 tcp dpt:80 2 ACCEPT all -- 0.0.0.0/0 0.0.0.0/0 state RELATED,ESTABLISHED 3 ACCEPT icmp -- 0.0.0.0/0 0.0.0.0/0 4 ACCEPT all -- 0.0.0.0/0 0.0.0.0/0 5 ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 state NEW tcp dpt:22 6 ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 state NEW tcp dpt:8080 7 ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 state NEW tcp dpt:8099 8 ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 state NEW tcp dpt:50031 9 REJECT all -- 0.0.0.0/0 0.0.0.0/0 reject-with icmp-host-prohibited Chain FORWARD (policy ACCEPT) num target prot opt source destination 1 REJECT all -- 0.0.0.0/0 0.0.0.0/0 reject-with icmp-host-prohibited Chain OUTPUT (policy ACCEPT) num target prot opt source destination [root@localhost sbin]#
命令介紹如下:
/sbin/iptables -I INPUT -p tcp --dport 8011 -j ACCEPT #開啟8011端口
/etc/rc.d/init.d/iptables save #保存配置
/etc/rc.d/init.d/iptables restart #重啟服務
查看端口是否已經開放
/etc/init.d/iptables status
#######################################################
其他方式:
查看防火牆的狀態:
/etc/init.d/iptables status
1) 重啟后生效
開啟: chkconfig iptables on
關閉: chkconfig iptables off
2) 即時生效,重啟后失效
開啟: service iptables start
關閉: service iptables stop
需要說明的是對於Linux下的其它服務都可以用以上命令執行開啟和關閉操作。
在開啟了防火牆時,做如下設置,開啟相關端口,
修改/etc/sysconfig/iptables 文件,添加以下內容:
-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT
-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT
這里應該也可以不重啟計算機:
#/etc/init.d/iptables restart
關閉防火牆服務即可:
查看防火牆信息:
#/etc/init.d/iptables status
關閉防火牆服務:
#/etc/init.d/iptables stop
-----簡單的修改,在開啟防火牆的情況下。放開對應端口,見下面紅色。
# Generated by iptables-save v1.4.7 on Mon Dec 26 16:43:03 2016
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [3:420]
-A INPUT -p tcp -m tcp --dport 22 -j ACCEPT
-A INPUT -p tcp -m tcp --dport 8999 -j ACCEPT
-A INPUT -p tcp -m tcp --dport 25 -j ACCEPT
-A INPUT -p tcp -m tcp --dport 8005 -j ACCEPT
COMMIT
# Completed on Mon Dec 26 16:43:03 2016
一、Linux下開啟/關閉防火牆命令
1、永久性生效,重啟后不會復原。
開啟: chkconfig iptables on
關閉: chkconfig iptables off
2、 即時生效,重啟后復原
開啟: service iptables start
關閉: service iptables stop
需要說明的是對於Linux下的其它服務都可以用以上命令執行開啟和關閉操作。
在當開啟了防火牆時,做如下設置,開啟相關端口,
修改/etc/sysconfig/iptables 文件,添加以下內容:
-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT
-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT
二、UBuntu關閉防火牆
iptables -A INPUT -i ! PPP0 -j ACCEPT
三、CentOS Linux 防火牆配置及關閉
執行”setup”命令啟動文字模式配置實用程序,在”選擇一種工具”中選擇”防火牆配置”,然后選擇”運行工具”按鈕,出現防火牆配置界面,將”安全級別”設為”禁用”,然后選擇”確定”即可.
或者用命令:
#/sbin/iptables -I INPUT -p tcp –dport 80 -j ACCEPT
#/sbin/iptables -I INPUT -p tcp –dport 22 -j ACCEPT
#/etc/rc.d/init.d/iptables save
這樣重啟計算機后,防火牆默認已經開放了80和22端口
這里應該也可以不重啟計算機:
#/etc/init.d/iptables restart
關閉防火牆服務即可:
查看防火牆信息:
#/etc/init.d/iptables status
關閉防火牆服務:
#/etc/init.d/iptables stop