How
to setup linux as router
You need two network interfaces in system (One can be pppoe).
1. Setup system gateway
Edit /etc/sysconfig/network, add gateway or gateway device such as below.
GATEWAY=192.168.0.1
or
GATEWAYDEV=ppp0
2. Turn on IP packet forwarding.
Edit /etc/sysctl.conf, modify below line.
net.ipv4.ip_forward = 1
3. Setup iptable (Only if your LAN IP is private IP and will forward to public IP)
The following examples assume that you are masquerading all computers on your private LAN 10.0.0 (i.e. 10.0.0.1, 10.0.0.2, etc.) and routing packets from that LAN to the Internet over your dial-up (ppp0) interface.
For iptables, type the following as root user:
# iptables -t nat -A POSTROUTING -o ppp0 -j MASQUERADE
# iptables -A FORWARD -s 10.0.0.0/24 -j ACCEPT
# iptables -A FORWARD -d 10.0.0.0/24 -j ACCEPT
# iptables -A FORWARD -s ! 10.0.0.0/24 -j DROP
# cp /etc/sysconfig/iptables /etc/sysconfig/iptables.old
# iptables-save > /etc/sysconfig/iptables
# /etc/init.d/network restart
# /etc/init.d/iptables restart
# iptables -L -n
Refer: http://etutorials.org/Linux+systems/red+hat+linux+bible+fedora+enterprise+edition/Part+IV+Red+Hat+Linux+Network+and+Server+Setup/Chapter+16+Connecting+to+the+Internet/Setting+up+Red+Hat+Linux+as+a+Router/
本文详细介绍了如何将Linux系统配置为路由器。主要内容包括:设置系统网关、开启IP包转发功能以及配置iptables(针对私有IP地址转换为公网IP的情况)。通过这些步骤,可以实现从局域网到互联网的数据包路由。

6358

被折叠的 条评论
为什么被折叠?



