linux firewalld 防火墙简单命令:
firewall-cmd --get-default-zone #查看当前默认区域
firewall-cmd –-set-default-zone=public #设置public为默认接口区域
systemctl start firewalld #启动
systemctl status firewalld #或者firewall-cmd –state 查看状态
sytemctl disable firewalld #停止并禁用开机启动
systemctl enable firewalld #设置开机启动
systemctl stop firewalld #禁用
firewall-cmd –version #查看版本
firewall-cmd –help #帮助信息
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 –-reload #更新防火墙规则
firewall-cmd –-complete-reload #断开再连接
firewall-cmd –-zone=public –-add-interface=eth0 #将接口添加到public区域 , 默认接口都在public。若加上–permanet则永久生效
firewall-cmd –-zone=pulic –-list-ports #查看所有打开的端口
firewall-cmd –-zone=pulic –-add-port=80/tcp #把tcp 80端口加入到区域
firewall-cmd –-zone=public –-add-service=http #把http服务加入到区域
firewall-cmd –-zone=public –-remove-service=http #移除http服务
firewall-cmd --permanent --zone=home --add-forward-port=port=22:proto=tcp:toaddr=127.0.0.2 #将home区域的ssh服务转发到 127.0.0.2
端口转发:
firewall-cmd --direct --add-rule ipv4 filter FWDI_external_allow 0 -j ACCEPT ##把ACCEPT规则添加进去
firewall-cmd --permanent --direct --add-rule ipv4 filter POSTROUTING 0 -t nat -s 10.10.0.0/24 -o eth0 -j MASQUERADE -t nat ##nat转发
firewall-cmd --zone=external --add-masquerade
firewall-cmd --zone=external --add-forward-port=port=22:proto=tcp:toport=3777 #首先启用伪装masquerade,然后把外部区域external的22端口转发到3777。
原文地址:http://blog.51cto.com/2475296/2095950