centos iptables 添加端口

 more /etc/redhat-release


1、firewalld的基本使用

启动: systemctl start firewalld

查看状态: systemctl status firewalld 

停止: systemctl disable firewalld



禁用: systemctl stop firewalld

 
2.systemctl是CentOS7的服务管理工具中主要的工具,它融合之前service和chkconfig的功能于一体。

启动一个服务:systemctl start firewalld.service
关闭一个服务:systemctl stop firewalld.service
重启一个服务:systemctl restart firewalld.service
显示一个服务的状态:systemctl status firewalld.service
在开机时启用一个服务:systemctl enable firewalld.service
在开机时禁用一个服务:systemctl disable firewalld.service
查看服务是否开机启动:systemctl is-enabled firewalld.service
查看已启动的服务列表:systemctl list-unit-files|grep enabled
查看启动失败的服务列表:systemctl --failed

3.配置firewalld-cmd

查看版本: firewall-cmd --version
查看帮助: firewall-cmd --help
显示状态: firewall-cmd --state
查看所有打开的端口: firewall-cmd --zone=public --list-ports
更新防火墙规则: firewall-cmd --reload
查看区域信息:  firewall-cmd --get-active-zones
查看指定接口所属区域: firewall-cmd --get-zone-of-interface=eth0
拒绝所有包:firewall-cmd --panic-on
取消拒绝状态: firewall-cmd --panic-off
查看是否拒绝: firewall-cmd --query-panic
 
那怎么开启一个端口呢
添加
firewall-cmd --zone=public --add-port=80/tcp --permanent    (--permanent永久生效,没有此参数重启后失效)
重新载入
firewall-cmd --reload
查看
firewall-cmd --zone= public --query-port=80/tcp
删除
firewall-cmd --zone= public --remove-port=80/tcp --permanent

firewall-cmd --zone=public --add-port=10001-10512/udp --permanent
CentOS 7系统中使用iptables放行端口,可按以下步骤操作: ### 1. 安装并启用iptables CentOS 7 默认使用firewalld防火墙,若要换回iptables防火墙,需关闭firewalld并安装iptables-services: ```bash yum install iptables-services ``` 关闭firewalld并启动iptables: ```bash systemctl stop firewalld systemctl disable firewalld systemctl start iptables systemctl enable iptables ``` 可通过执行状态查询命令验证安装启动是否成功: ```bash systemctl status iptables.service ``` 若显示类似如下内容,则说明安装启动成功: ```plaintext ● iptables.service - IPv4 firewall with iptables Loaded: loaded (/usr/lib/systemd/system/iptables.service; enabled; vendor preset: disabled) Active: active (exited) since Mon 2019-03-18 02:18:04 PDT; 20h ago Process: 6029 ExecStart=/usr/libexec/iptables/iptables.init start (code=exited, status=0/SUCCESS) Main PID: 6029 (code=exited, status=0/SUCCESS) CGroup: /system.slice/iptables.service Mar 18 02:18:03 localhost.localdomain systemd[1]: Starting IPv4 firewall with... Mar 18 02:18:04 localhost.localdomain iptables.init[6029]: iptables: Applying... Mar 18 02:18:04 localhost.localdomain systemd[1]: Started IPv4 firewall with ... Hint: Some lines were ellipsized, use -l to show in full. ``` ### 2. 编辑防火墙配置文件 使用以下命令编辑防火墙配置文件: ```bash vi /etc/sysconfig/iptables ``` 在文件中添加需要放行的端口规则,例如放行80、8080、3306、3690端口添加端口22规则的上面或者下面,不要放在最后,不然可能不起作用。输入以下规则: ```plaintext -A INPUT -p tcp -m state --state NEW -m tcp --dport 8080 -j ACCEPT -A INPUT -p tcp -m state --state NEW -m tcp --dport 3306 -j ACCEPT -A INPUT -p tcp -m state --state NEW -m tcp --dport 80 -j ACCEPT -A INPUT -p tcp -m state --state NEW -m tcp --dport 3690 -j ACCEPT ``` 编辑时,输入 `i` 进入插入状态,编辑完成后,按 `esc` 退出插入状态,输入 `:wq` 保存并退出。 ### 3. 重启iptables并验证规则 全部修改完之后,重启iptables使配置生效: ```bash service iptables restart ``` 可通过以下命令验证规则是否生效: ```bash iptables -L ``` ### 4. 持久化配置 为了确保重启系统后配置仍然生效,需要进行持久化配置。可通过以下命令保存当前的iptables规则: ```bash service iptables save ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值