ZZ Quick-Tip: Linux NAT in Four Steps using iptables

简介: 4步搞定linux nat,其中eth0是外网口,eth1是内网口 1、First you need to tell your kernel that you want to allow IP forwarding.

4步搞定linux nat,其中eth0是外网口,eth1是内网口

1、First you need to tell your kernel that you want to allow IP forwarding.

echo 1 > /proc/sys/net/ipv4/ip_forward
Then you’ll need to configure iptables to forward the packets from your internal network, on /dev/eth1, to your external network on /dev/eth0.

2、You do this will the following commands:

/sbin/iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
/sbin/iptables -A FORWARD -i eth0 -o eth1 -m state –state RELATED,ESTABLISHED -j ACCEPT
/sbin/iptables -A FORWARD -i eth1 -o eth0 -j ACCEPT
You should now be NATing. You can test this by pinging an external address from one of your internal hosts. The last step is to ensure that this setup survives over a reboot. Obviously you should only do these last two steps if your test is a success.

3、You will need to edit /etc/sysconfig/iptables-config and make sure IPTABLES_MODULES_UNLOAD, IPTABLES_SAVE_ON_STOP, and IPTABLES_SAVE_ON_RESTART are all set to ‘yes’.

4、设置iptables自动启动

After all that is done, you should probably do a test reboot to ensure that you’ve done everything correctly. If you find any errors on this page or this does not work for you please feel free to E-mail me directly at frank@revsys.com.

相关实践学习
每个IT人都想学的“Web应用上云经典架构”实战
本实验从Web应用上云这个最基本的、最普遍的需求出发,帮助IT从业者们通过“阿里云Web应用上云解决方案”,了解一个企业级Web应用上云的常见架构,了解如何构建一个高可用、可扩展的企业级应用架构。
目录
相关文章
|
Linux 网络性能优化 网络安全
Linux(openwrt)下iptables+tc工具实现网络流量限速控制(QoS)
通过以上步骤,您可以在Linux(OpenWrt)系统中使用iptables和tc工具实现网络流量限速控制(QoS)。这种方法灵活且功能强大,可以帮助管理员有效管理网络带宽,确保关键业务的网络性能。希望本文能够为您提供有价值的参考。
3389 28
|
机器学习/深度学习 安全 网络协议
Linux防火墙iptables命令管理入门
本文介绍了关于Linux防火墙iptables命令管理入门的教程,涵盖了iptables的基本概念、语法格式、常用参数、基础查询操作以及链和规则管理等内容。
628 73
|
负载均衡 网络协议 Linux
|
运维 网络协议 安全
Linux安全运维--一篇文章全部搞懂iptables
Linux安全运维--一篇文章全部搞懂iptables
427 1
|
域名解析 网络协议 Linux
在Linux中,iptables有哪相关的命令?
在Linux中,iptables有哪相关的命令?
|
网络协议 Linux 应用服务中间件
如何使用Iptables在Linux网关上转发端口
如何使用Iptables在Linux网关上转发端口
583 5
|
负载均衡 算法 Linux
在Linux中,LVS-NAT模式的原理是什么?
在Linux中,LVS-NAT模式的原理是什么?
|
Linux 网络安全
在Linux中,iptables和firewalld两种防火墙如何使用?
在Linux中,iptables和firewalld两种防火墙如何使用?
|
负载均衡 算法 Linux
在Linux中,LVS-NAT模型的特性是什么?
在Linux中,LVS-NAT模型的特性是什么?
|
负载均衡 Linux 网络虚拟化
在Linux中,什么是NAT,常见分为那几种,DNAT与SNAT有什么不同,应用事例有那些?
在Linux中,什么是NAT,常见分为那几种,DNAT与SNAT有什么不同,应用事例有那些?