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

  • 10
    点赞
  • 71
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值