双网卡linux快速搭建nat主机共享上网!

来源:互联网 发布:java 反射 混淆 编辑:程序博客网 时间:2024/04/30 03:54

 

这是在实验室搭建局域网时的配置写在这里吧,等在回忆那段大学生活时还是很美好的!

环境:外网IP 202.206.249.186 子网掩码 255.255.255.0 默认网关 202.206.249.1
          内网IP192.168.0.1           子网掩码 255.255.255.0网关不添
[root@localhost ~]# echo "1" > /proc/sys/net/ipv4/ip_forward
[root@localhost ~]# iptables -F
 [root@localhost ~]# iptables -t nat -F
[root@localhost ~]# iptables -t mangle -F
[root@localhost ~]# iptables -X
[root@localhost ~]# iptables -t nat -X
[root@localhost ~]# iptables -t mangle -X
[root@localhost ~]# iptables -P INPUT ACCEPT
[root@localhost ~]# iptables -P OUTPUT ACCEPT
[root@localhost ~]# iptables -P FORWARD ACCEPT
[root@localhost ~]# iptables -t nat -A POSTROUTING -s 192.168.0.0/24 -o eth0 -j SNAT --to 202.206.249.186
保存
iptables-save>nat-1.1
service iptables save