1、iptables 配置 NAT转发 cycwll#vim /etc/sysctl.conf 配置路由转发。net.ipv4.ip_forward = 0修改为net.ipv4.ip_forward = 1 允许内置路由#sysctl -p 更新NAT#iptables -t nat -A POSTROUTING -s 192.168.1.0/24 -o ppp0 -j SNAT -to 123.184.176.205#service iptables save192.168.1.223的网关设置成192.168.1.254(NAT的服务器)端口映射:#iptables -t nat -A PR
2、EROUTING -dst 123.184.176.205 -p tcp -dport 9901 -j DNAT -to-destination 192.168.1.223:9901可以先让所有链默认ACCEPT,以免影响调试iptables -P FORWARD ACCEPTiptables -P OUTPUT ACCEPTiptables -P INPUT ACCEPT开放DNS端口iptables -A FORWARD -p tcp -dport 53 -j ACCEPTiptables -A FORWARD -p udp -dport 53 -j ACCEPT由于是PPPOE,没有固定
3、IP地址,所以需要自己写个脚本,检测一下外网IP是否变化,如果发生变化则主动到ddns访问注册。#/bin/shPPPIP_OLD=ifconfig ppp0 |grep -Po (?=addr:).*(?=P-t)while truedo sleep 600 PPPIP_NEW=ifconfig ppp0 |grep -Po (? /etc/iproute2/rt_table(这个是添加到文件,执行一次即可)# ip route replace default via 222.168.1.2 table DIANXIN# ip rule add fwmark 1 table DIANXIN(
4、这个注意顺序,用ip rule可以查看)# iptables -t nat -F# iptables -t mangle -F# iptables -t mangle -A PREROUTING -i eth0 -s 192.168.0.0/24 -d 222.222.5.0/15 -j MARK -set-mark 1# iptables -t mangle -A PREROUTING -i eth0 -s 192.168.0.0/24 -d 222.240.0.0/13 -j MARK -set-mark 1# iptables -t nat -A POSTROUTING -s 192.1
5、68.0.0/24 -d 222.222.5.0/15 -j SNAT -to $DIANXIN# iptables -t nat -A POSTROUTING -s 192.168.0.0/24 -d 222.240.0.0/13 -j SNAT -to $DIANXIN# iptables -t nat -A POSTROUTING -s 192.168.0.0/24 -j SNAT -to $接网通线路网卡的地址# ip route flush cache2.1.6 添加相似路由if $ALLOW_ACCESS_CLIENT != ; then for LAN in $ALLOW_ACC
6、ESS_CLIENT; do iptables -A FORWARD -p tcp -m multiport -s $LAN -o $ETH_WAN -dport $PORT -j ACCEPT iptables -A FORWARD -p udp -m multiport -s $LAN -o $ETH_WAN -dport $PORT -j ACCEPT iptables -A FORWARD -p tcp -m multiport -i $ETH_WAN -sport $PORT -j ACCEPT iptables -A FORWARD -p udp -m multiport -i $
7、ETH_WAN -sport $PORT -j ACCEPT donefi2.3 保存iptables-save -c /etc/sysconfig/iptables1.5 转发设置/etc/sysctl.conf# Controls IP packet forwardingnet.ipv4.ip_forward = 1filter.ip_conntrack_max = 1048576filter.ip_conntrack_tcp_timeout_established = 3002. iptables配置2.1 iptables初始化iptables -t nat -Fiptables -F
8、iptables -Xiptables -P INPUT ACCEPTiptables -P FORWARD ACCEPTiptables -P OUTPUT ACCEPTiptables -N NEWCONN2.2 NAT转换2.2.1 首先将从两个WAN口出去的数据包进行IP伪装masquerade/sbin/iptables -t nat -A postrouting -o eth1 -j masquerade/sbin/iptables -t nat -A postrouting -o eth2 -j masquerade2.1.2 SNATiptables -t nat -A POSTROUTING -s 内部IP地址/子网 -o $OUTGOING -j SNAT-to $IPPOOL2.1.3 一个网段的电信网通自动切换iptables -t nat -
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1