Linux Share a Dial Up Internet Connection

Q. My modem is connected to CentOS Linux server. I’m using wvdial to connect to my ISP; I’d like to connect my laptop via same modem. How do I share a dial up Internet account?

A.. You can use iptables. It supports – IP Masquerading i.e. network address translation (NAT) to share internet.

ADVERTISEMENTS

Connect laptop to Linux box using hub / switch / cross-over Ethernet cable

Dial out using wvdial

Make sure ppp0 is up

Once connected type the following two command at a shell prompt to share ppp0 interface:
# sysctl -w net.ipv4.ip_forward=1
# iptables --table nat --append POSTROUTING --out-interface ppp0 -j MASQUERADE

You need to add above rules to your existing iptables scripts. You can also create a script call share.ppp0 at /etc/ppp/ip-up.d/ with above two lines. This script run by the pppd after the link is established.
# cat > /etc/ppp/ip-up.d/share.ppp0
Append following code:
#!/bin/sh
sysctl -w net.ipv4.ip_forward=1
iptables --table nat --append POSTROUTING --out-interface ppp0 -j MASQUERADE
# add other firewall rules below
# ....

Save and close the file.

Client Computer Setup

Login to laptop, set Linux server IP address as default gateway IP. Also setup nameserver IP address (NS1 / NS2). Run ping command to test connectivity:
$ ping google.com
$ ping linux-box.ip
$ nslookup google.com

🐧 Get the latest tutorials on SysAdmin, Linux/Unix, Open Source/DevOps topics:
CategoryList of Unix and Linux commands
File Managementcat
FirewallCentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network Utilitiesdig 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 VPNCentOS 8 Debian 10 Firewall Ubuntu 20.04

ADVERTISEMENTS
1 comment… add one

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre>, <code>...</code> and <kbd>...</kbd> for code samples.