This step by step howto will help you to setup Linux as router only in two (2) minutes. I'm assuming that your setup is as follows:
(A) You are using RedHat Linux, FC linux/Debian Linux (this should work with ALL Other distros as well :D )
(B) ppp0 is internet interface (connected to Modem for example) and eth0 connected to your internal lan (connected to your HUB/Switch for example)
My Linux --> eth0 Box --> ppp0 (comes up when you dial up into ISP)
Step # 1 Turn on ip forwarding in kernel
1) Open linux kernel configuration file:
# vi /etc/sysctl.conf
2) Add/modify following line:
net.ipv4.ip_forward = 1
Step # 2 Restart network
# /etc/init.d/network restart
OR
# service network restart
(Note first dial to ISP using wvdial or similar program )
Step # 3 Setup IP forwarding and Masquerading (to act as router), you need to use NAT option of iptables as follows:
# iptables --table nat --append POSTROUTING --out-interface ppp0 -j MASQUERADE
# iptables --append FORWARD --in-interface eth0 -j ACCEPT
Step # 4 You are done! Test it with ping or dig:
# ping your-isp.com
# dig www.nixcraft.com
# dig yahoo.com
Step # 5 Point all client to your eth0 IP address as Router/Gateway.
Step # 6 Put code described in step # 3 to script and call it from /etc/rc.local
You should follow me on twitter here or grab rss feed to keep track of new changes.
Featured Articles:
- 30 Handy Bash Shell Aliases For Linux / Unix / Mac OS X
- Top 30 Nmap Command Examples For Sys/Network Admins
- 25 PHP Security Best Practices For Sys Admins
- 20 Linux System Monitoring Tools Every SysAdmin Should Know
- 20 Linux Server Hardening Security Tips
- Linux: 20 Iptables Examples For New SysAdmins
- Top 20 OpenSSH Server Best Security Practices
- Top 20 Nginx WebServer Best Security Practices
- 20 Examples: Make Sure Unix / Linux Configuration Files Are Free From Syntax Errors
- 15 Greatest Open Source Terminal Applications Of 2012

- My 10 UNIX Command Line Mistakes
- Top 10 Open Source Web-Based Project Management Software
- Top 5 Email Client For Linux, Mac OS X, and Windows Users
- The Novice Guide To Buying A Linux Laptop













{ 1 comment… read it below or add one }
Hi
this configuration is not working for me
i have USB modem, and eth0
i am dialing with wvdial, using centos 5.2
connection is working, i can use internet on the same machine, but i am not able to enable the routing using your post, tried many post but i am not able to manage it
my ppp0 is having dynamic IP address when ever i connect to the internet
eth0 is connected to my local lan haivng ip address to 192.168.0.1/192.168.0.10
get me some thing, i am very much stuck
Thanks in advance