系统相关
首页 > 系统相关> > ubuntu使用iptables 持久化

ubuntu使用iptables 持久化

作者:互联网


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不行,需要看看。

 

标签:iptables,REDIRECT,持久,tcp,nat,ubuntu,dport,81
来源: https://www.cnblogs.com/liuxm2017/p/11152738.html