首页 > 代码库 > centos 7 防火墙和端口配置
centos 7 防火墙和端口配置
centos 7 防火墙和端口配置
--解决 RHEL 7/ CentOS 7/Fedora 出现Unit iptables.service failed to load
# 第一步,关闭firewall:
CentOS 7.0默认使用的是firewall作为防火墙,这里改为iptables防火墙。
systemctl stop firewalld.service #停止firewallsystemctl disable firewalld.service #禁止firewall开机启动
# 第二步,安装iptables-services:
yum install iptables-services
# 第三步,启用iptables-services:
root@vm-xiluhua ~# systemctl enable iptables #启用Created symlink from /etc/systemd/system/basic.target.wants/iptables.service to /usr/lib/systemd/system/iptables.service.root@vm-xiluhua ~# service iptables save iptables: Saving firewall rules to /etc/sysconfig/iptables:[ 确定 ]root@vm-xiluhua ~# service iptables status #查看状态Redirecting to /bin/systemctl status iptables.service● iptables.service - IPv4 firewall with iptables Loaded: loaded (/usr/lib/systemd/system/iptables.service; enabled; vendor preset: disabled) Active: inactive (dead)root@vm-xiluhua ~# service iptables start #启动Redirecting to /bin/systemctl start iptables.serviceroot@vm-xiluhua ~# service iptables statusRedirecting to /bin/systemctl status iptables.service● iptables.service - IPv4 firewall with iptables Loaded: loaded (/usr/lib/systemd/system/iptables.service; enabled; vendor preset: disabled) Active: active (exited) since 一 2016-10-03 15:41:24 CST; 8s ago Process: 9913 ExecStart=/usr/libexec/iptables/iptables.init start (code=exited, status=0/SUCCESS) Main PID: 9913 (code=exited, status=0/SUCCESS) 10月 03 15:41:24 vm-xiluhua systemd[1]: Starting IPv4 firewall with iptables...10月 03 15:41:24 vm-xiluhua iptables.init[9913]: iptables: Applying firewall rules: [ 确定 ]10月 03 15:41:24 vm-xiluhua systemd[1]: Started IPv4 firewall with iptables.
# 第4步,编辑iptables-services,加入端口配置(开启端口)
root@vm-xiluhua ~# vi /etc/sysconfig/iptables
-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 6379 -j ACCEPT #redis
-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 21 -j ACCEPT #ftp
-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT #ssh
-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 11211 -j ACCEPT #memcached
-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT #mysql
root@vm-xiluhua ~# service iptables save #保存规则到iptablesiptables: Saving firewall rules to /etc/sysconfig/iptables:[ 确定 ]root@vm-xiluhua ~# service iptables restart #重新启动Redirecting to /bin/systemctl restart iptables.service
centos 7 防火墙和端口配置
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。