笔者对iptables常用的高级案例进行了一些分享,本文不是基础的iptables教程,主要是对一些数通领域常用的方案进行了一些分享,如需要详细了解一些方案的细节,可以联系笔者。
1、多网口路由转发方案
brctl addbr br0 brctl addif br0 eth0 brclt addlif br0 eth1 brclt addif br0 ath0 ifconfig br0 192.168.1.1 mask 255.255.255.0 ifconfig br0 up route add default gw eth2 |
2、IP 地址自动部署
brctl addbr br0 brctl addif br0 eth0 brclt addlif br0 eth1 brclt addif br0 ath0 ifconfig br0 192.168.1.1 mask 255.255.255.0 ifconfig br0 up udhcpd –i br0 & route add default gw eth2 |
3、多人同时上网
brctl addbr br0 brctl addif br0 eth0 brclt addlif br0 eth1 brclt addif br0 ath0 ifconfig br0 192.168.1.1 mask 255.255.255.0 ifconfig br0 up udhcpd -i br0 & route add default gw eth2 iptables -t nat -A POSTROUTING -s 192.168.1.0/255.255.225.0 -o -j MASQUERADE |
3、DNS代理
brctl addbr br0 brctl addif br0 eth0 brclt addlif br0 eth1 brclt addif br0 ath0 ifconfig br0 192.168.1.1 mask 255.255.255.0 ifconfig br0 up udhcpd -i br0 & route add default gw eth2 dnsmasq & iptables -t nat -A POSTROUTING –s 192.168.1.0/255.255.225.0 -o -j MASQUERADE iptables –t nat –A PREROUTING –i br0 –p udp –-dport 53 -j REDIRECT --to-port 53 |
3、用户URL跟踪
brctl addbr br0 brctl addif br0 eth0 brclt addlif br0 eth1 brclt addif br0 ath0 ifconfig br0 192.168.1.1 mask 255.255.255.0 ifconfig br0 up udhcpd -i br0 & route add default gw eth2 dnsmasq & squid & iptables -t nat -A POSTROUTING –s 192.168.1.0/255.255.225.0 -o –j MASQUERADE iptables –t nat –A PREROUTING –i br0 –p udp –-dport 53 -j REDIRECT --to-port 53 iptables -t nat -A PREROUTING -d !192.168.1.1 -p tcp --dport 80-j DNAT --to-destionation 192.168.1.1:8080 |
3、portal推送
brctl addbr br0 brctl addif br0 eth0 brclt addlif br0 eth1 brclt addif br0 ath0 ifconfig br0 192.168.1.1 mask 255.255.255.0 ifconfig br0 up udhcpd -i br0 & route add default gw eth2 dnsmasq & lighttpd & iptables -t nat -A POSTROUTING –s 192.168.1.0/255.255.225.0 -o –j MASQUERADE iptables –t nat –A PREROUTING –i br0 –p udp –-dport 53 -j REDIRECT --to-port 53 iptables -t nat -A PREROUTING -d !192.168.1.1 -p tcp --dport 80 -j DNAT --to-destionation 192.168.1.1 //该功能可以和内核模块关联使用,将认证通过的IP配置到内核模块,内核模块hook报文之后进行IP匹配,匹配成功之后设置skb->mark,后面的iptbables规则可以加上mark的匹配,让认证通过的IP正常上网,其他IP正常推送portal。 |