Configure Linux As a Router

来源:互联网 发布:amada折弯机编程教程 编辑:程序博客网 时间:2024/05/22 01:57
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/

原创粉丝点击