首页 > 系统服务 > 详细

ubuntu使用iptables 持久化

时间:2019-07-08 18:00:49      阅读:342      评论:0      收藏:0      [点我收藏+]


iptables 持久化

 

安装持久化工具
apt-get install iptables-persistent

 

Ubuntu 16.04 调用语法
netfilter-persistent save
netfilter-persistent reload

 

一键清除iptables规则
cat clear_iptables_rule.sh
#!/bin/bash
iptables -F
iptables -X
iptables -Z
iptables -P INPUT ACCEPT
iptables -P OUTPUT ACCEPT
iptables -P FORWARD ACCEP

 

iptables 转发请求到80端口
1.使用DNAT实现
iptables -t nat -A PREROUTING -p tcp -i ens33 -d 192.168.122.128 --dport 8089 -j DNAT --to 192.168.122.128:80
2.使用redirect实现
iptables -t nat -A PREROUTING -p tcp --dport 8088 -j REDIRECT --to-port 80

====================

iptables 端口转发

1. 所有的81请求转发到了8080上.

# iptables -t nat -A PREROUTING -p tcp --dport 81 -j REDIRECT --to-ports 8080
1
# iptables -t nat -A PREROUTING -p tcp --dport 81 -j REDIRECT --to-ports 8080
如果需要本机也可以访问,则需要配置OUTPUT链:

iptables -t nat -A OUTPUT -p tcp --dport 81 -j REDIRECT --to-ports 8080
1
iptables -t nat -A OUTPUT -p tcp --dport 81 -j REDIRECT --to-ports 8080
原因:外网访问需要经过PREROUTING链,但是localhost不经过该链,因此需要用OUTPUT,或者POSTROUTING。POSTROUTING不行,需要看看。

 

ubuntu使用iptables 持久化

原文:https://www.cnblogs.com/liuxm2017/p/11152738.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!