在新的linux系统/etc/sysconfig/iptables是没有这个 ,因为没有配置过防火墙,所以没有这个文件
编辑/etc/sysconfig/iptables 添加端口
如果是新装系统 可能在新安装的linux系统中,防火墙默认是被禁掉的,一般也没有配置过任何防火墙的策略,所有不存在/etc/sysconfig/iptables文件。
解决办法:
[root@localhost~]#iptables -N RH-Firewall-1-INPUT //添加政策
[root@localhost~]# service iptables save //保存
[root@localhost~]#vi /etc/sysconfig/iptables //编辑
vim /etc/sysconfig/iptables 编辑防火墙文件
service iptables save 保存防火墙设置
service iptables restart 重启防火墙使生效
/etc/init.d/iptables restart 重启防火墙使生效
Linux下打开和关闭防火墙
1.及时生效,重启后复原
关闭:service iptables stop 开启:service iptalbes start 查看状态:service iptables status(关闭状态的话会提示firewal is not running)
2.非及时性生效,重启后永久性生效
关闭:chkconfig iptbales off 开启:chkconfig iptables on 查看状态:chkconfig iptables --list
在开启了防火墙时,做如下设置,开启相关端口,
修改/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
shutdown -h now:立马关机
reboot:重启
配置防火墙,开启80端口、3306端口
vi /etc/sysconfig/iptables
-A INPUT -m state –state NEW -m tcp -p tcp –dport 80 -j ACCEPT(允许80端口通过防火墙)
-A INPUT -m state –state NEW -m tcp -p tcp –dport 3306 -j ACCEPT(允许3306端口通过防火墙)
特别提示:很多网友把这两条规则添加到防火墙配置的最后一行,导致防火墙启动失败,正确的应该是添加到默认的22端口这条规则的下面
添加好之后防火墙规则如下所示:
######################################
# Firewall configuration written by system-config-firewall
# Manual customization of this file is not recommended.
*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 tcp -p tcp –dport 80 -j ACCEPT
-A INPUT -m state –state NEW -m tcp -p tcp –dport 3306 -j ACCEPT
-A INPUT -j REJECT –reject-with icmp-host-prohibited
-A FORWARD -j REJECT –reject-with icmp-host-prohibited
COMMIT
#####################################
/etc/init.d/iptables restart #最后重启防火墙使配置生效
linux 配置防火墙 开启80/3306端口
猜你喜欢
转载自blog.csdn.net/qq_29883183/article/details/102650527
今日推荐
周排行