centos6、7下iptables、firewalld实验

iptables

实验一:端口控制

iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT    #允许已建立的或相关连的通行

开放80端口:iptables -A INPUT -p tcp --dport 80 -j ACCEPT

开放80端口:iptables -A INPUT -p tcp --dport 80 -s 192.168.211.0/24  -j ACCEPT   --->允许211网段访问80端口

开放连续端口:iptables -A INPUT -p tcp --dport 10000:11000 -j ACCEPT

iptables -I INPUT -s 123.45.6.7 -j DROP       #屏蔽单个IP的命令

iptables -I INPUT -s 124.45.0.0/16 -j DROP    #封IP段即从123.45.0.1到123.45.255.254的命令

iptables -I INPUT -p tcp –dport 80 -s 124.115.0.0/24 -j DROP  #屏蔽该网段访问80端口


删除规则:
iptables -L -n --line-number    --->列出规则
iptables -D INPUT 4

实验二、端口转发
server
eth0:192.168.211.128  -->public
eht1:192.168.112.129

打开转发功能
vi /etc/sysctl.conf
net.ipv4.ip_forward = 1
#sysctl -p   --->修改立即生效

输入命令前执行:
iptables -F    清除iptables内置规则
iptables -X    删除用户自定义的规则链
iptables -Z    链的计数器清零

iptables -t nat -A POSTROUTING -s 192.168.112.0/24 -o eth0 -j SNAT --to-source 192.168.211.128   (eth0为外网网卡)

client
eth0:192.168.112.128
gateway:192.168.112.129


firewalld

systemctl status firewalld   --->查看防火墙状态
firewall-cmd --list-all		--->列出防火墙规则
firewall-cmd --add-service=http	--->临时开放http服务(80端口)
firewall-cmd --add-service=http --permanent	--->永久开放80端口
firewall-cmd --reload		--->重新加载防火墙规则
firewall-cmd --get-services		--->列出服务

firewall-cmd --add-port=10000-11000/tcp	--->开放10000-11000端口(临时)
firewall-cmd --add-port=10000-11000/tcp --permanent	--->开放10000-11000端口(永久)

删除:
--add-   ---> --remove-
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值