Centos7 防火墙常用配置及网络设置
firewall常用命令:
1、重启、关闭、开启、firewalld.serverice 服务
service firewalld restart 重启
centos vim命令service firewalld start 开启
service firewalld stop 关闭
systemctl status firewalld
systemctl stop firewalld 关闭
systemctl start firewalld 开启
systemctl restart firewalld 重启
systemctl disable firewalld 关闭开机启动
2、查看状态
firewall-cmd --state
3、查看防火墙规则
firewall-cmd --list-all
Centos 切换为iptables防火墙:
切换到iptables首先应该关掉默认的firewalld,然后安装iptables服务。
1、关闭firewall:
service firewalld stop systemctl disable firewalld.service #禁止firewall开机启动
2、安装iptables防火墙
yum install iptables-services #安装
3、编辑iptables防火墙配置
vi /etc/sysconfig/iptables #编辑防火墙配置文件
下边是一个完整的配置文件:
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
:
wq #保存退出
service iptables start #开启systemctl enable iptables.service #设置防火墙开机启动iptables相关操作
# 查看iptables状态
service iptables status
#停止iptables
systemctl stop firewalld.service
#禁用iptables
systemctl disable firewalld.service
firewalld相关操作
#查看firewalld状态
systemctl status firewalld.service
#关闭firewalld
systemctl stop firewalld.service
#永久关闭firewalld
systemctl disable firewalld.service
1.查看防火墙状态
firewall-cmd --state
2.关闭防火墙
systemctl stop firewalld.service
3.开启防火墙
systemctl start firewalld.service
4.禁止开机启动启动防火墙
systemctl disable firewalld.service
5.开放端口号
firewall-cmd --zone=public--add-port=80/tcp --permanent
需要关闭防火墙,后再次开启(重启方能生效)
注意:
centos7 安装nginx后需要开放80端口
firewall-cmd --zone=public--add-port=80/tcp --permanent
centos7安装mysql后, 用navicat 远程链接mysql数据库,则需要开放3306端口
firewall-cmd --zone=public--add-port=3306/tcp –permanent
CentOS7 系统网络设置
cd /etc/sysconfig/network-scripts/
编辑ifcfg-lo文件
vim ifcfg-lo
vim ifcfg-enp0s3
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论