Centos7下没有iptables文件
在安装tomcat的时候最后出现了需要开放8080端口,发现默认的Centos7并没有iptables文件,这里我来说下这种情况怎么办;
因为Centos7默认使用的是firewall
作为防火墙,把它停掉再安装iptable
命令如下:
systemctl stop firewalld
systemctl mask firewalld
yum install -y iptables
yum install iptables-services
现在就看到/etc/sysconfig/
目录下就有iptables文件了,我们就可以进行下一步配置了;
配置完成之后开启服务
systemctl start iptables.service
systemctl restart iptables.service // 重启防火墙使配置生效
systemctl enable iptables.service // 设置防火墙开机启动
关于iptables的相关命令
service iptables status #检查是否安装了iptables
yum install -y iptables #安装iptables
yum update iptables #升级iptables
yum install iptables-services #安装iptables-services
systemctl disable iptables #禁止iptables服务
systemctl stop iptables #暂停服务
systemctl enable iptables #解除禁止iptables
systemctl start iptables #开启服务
我这边处理完之后还是不行,而且还影响到了现有服务器上的网站运行,然后进行了下一步排查;
查看端口监听状态
[root@momo sysconfig]# netstat -lntup
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 1718/nginx: master
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1169/sshd
tcp 0 0 0.0.0.0:443 0.0.0.0:*
tcp6 0 0 :::3306 :::* LISTEN 1008/mysqld
udp 0 0 0.0.0.0:68 0.0.0.0:* 784/dhclient
udp 0 0 172.17.101.100:123 0.0.0.0:* 907/ntpd
udp 0 0 127.0.0.1:123 0.0.0.0:* 907/ntpd
udp 0 0 0.0.0.0:123 0.0.0.0:* 907/ntpd
udp 0 0 0.0.0.0:19791 0.0.0.0:* 784/dhclient
udp6 0 0 :::32332 :::* 784/dhclient
udp6 0 0 :::123 :::* 907/ntpd
[root@momo sysconfig]#
发现8080端口并没有被监听;
先关闭防火墙
systemctl stop iptables
我备份了下规则然后执行了iptables -F
命令清空一下
之后将开启的端口号重新写入iptables
文件;重启下服务
tomcat的8080端口首页访问就正常了,网站也可以正常访问了;