iptables 代理设置
代理: 开启转发:echo 1 > /proc/sys/net/ipv4/ip_forward iptables -t nat -A POSTROUTING -s 192.168.1.0/24 -o eth0(外网网卡) -j SNAT --to(外网地址) 备用:iptables -t nat -A POSTROUTING -s 192.168.10.0/24 -o eth0 -j MASQUERADE
备用:iptables -t nat -A POSTROUTING -s 192.168.10.0/24 -j MASQUERADE
映射内部web: iptables -t nat -A PREROUTING -d (外网地址) -p tcp --dport 80 -j DNAT --to 10.1.120.251
另:
0. 环境
em1:10.10.120.11
em2:公网地址
1. 在线关闭selinux
[root@localhost ~]# setenforce 0
2. 开启内核转发
[root@localhost ~]# vi /etc/sysctl.conf
# Controls IP packet forwarding
net.ipv4.ip_forward = 1
3. 配置转发网卡
em2 接入外网
[root@localhost ~]# iptables -t nat -A POSTROUTING -o em2 -j MASQUERADE
4. 测试
route add default gw 10.10.120.11
ping 58.215.221.179
5. 保存配置文件
[root@localhost src]# chkconfig --level 235 iptables on
[root@localhost src]# /etc/init.d/iptables save
iptables:将防火墙规则保存到 /etc/sysconfig/iptables: [确定]