Howto Setup Linux as router for ppp dial up (PSTN/ISDN) connections

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 😀 )

(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
# 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
# dig
# dig

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

🐧 Get the latest tutorials on Linux, Open Source & DevOps via RSS feed or Weekly email newsletter.

🐧 1 comment so far... add one
CategoryList of Unix and Linux commands
Disk space analyzersncdu pydf
File Managementcat
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network UtilitiesNetHogs dig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04
1 comment… add one
  • Suketu Feb 4, 2009 @ 17:53

    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

    get me some thing, i am very much stuck
    Thanks in advance

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre> for code samples. Still have questions? Post it on our forum