linux中防火墙配置详解之(iptables)
iptables
防火墙中有三张表(iptables) 名称分别是 filter 包含 input forward output nat (net address transfer) 地址转换 包含 input prerouting postouting output mangle 包含 input prerouting forward postouting output
input nat未经过内核 filter经过了内核 forward 是数据传递(经过内核) postouting 路由之后 prerouting 路由之前 DNAT directory n a t SNAT 源地址转换
mangle 是前两个表不够用的时候 做的说明 可以用五个表 一般不常用
nat一般是和本机内核无关的 filter 都是经过内核的
systemclt stop firewalld mask
yum install iptables-servives
systemctl start iptables enable
iptables -nL n是不作解析 opt参数
iptables -t nat -nL 查看单一表单
不指定默认是filter 表
vim /etc/sysconfig/iptables 配置文件 iptables -F 刷掉所有策略
service iptables save 刷掉之后需要保存
iptables -nL 如果没有策略 默认policy策略 iptables -vnL
iptables -P INPUT DROP 不接收
iptables -P INPUT ACCEPT
iptables -N westos 增加附加列 iptables -E WESTOS 改名 iptables -X WESTOS 删除
iptables -t filter -A INPUT -s 172.25.254.250 -p tcp --dport 22 -j REJECT
和上面一样 不允许访问22端口的ssh
如果只能让250连接 iptables -A INPUT -j REJECT所有人不能访问 iptables -A INPUT -s 172.25.254.250 -p tcp --dport 22 -j ACCEPT
A 加入策略对后面 I 是加入策略最前面 必须要写条数 iptables -I INPUT 1 -s 172.25.254.250 -p tcp --dport 22 -j ACCEPT 不写数字 默认第一个
iptables -D INPUT 3 删除第三条 iptables -R INPUT 2 -j ACCEPT 更改条目
iptables -A INPUT -s !172.25.254.250 -p tcp --dport 22 -j ACCEPT !表示除了
下面进行伪装和转换地址 iptables -t nat -A POSTROUTING -o eth0 -j SNAT --to-source 172.25.254.212 iptables -t nat -A PREROUTING -i eth0 -j DNAT --to-dest 1.1.1.112
路由机 1.1.1.212& 172.25.254.212 server测试时候必须把网管设置成路由机 测试的时候 用server 1.1.1.112 连接 外网 172.25.254.12 这时候在172.25.254.12上w -i 显示的地址是172.25.254.212 这样就是伪装了 然后用server 112 连接 1.1.1.212 其实是连接到了1.1.1.112