Setting Up a PPPoE Server on Ubuntu
Environment
Tested on:
- Ubuntu 14.04 32-bit
- Ubuntu 16.04 64-bit
- Ubuntu 20.04 64-bit
Package Installation
sudo apt-get update
sudo apt-get install pppoe-server
sudo apt-get install pppoe
Configuration Files
/etc/ppp/options
sudo vim /etc/ppp/options
Configuration content:
ms-dns 8.8.8.8
ms-dns 8.8.4.4
asyncmap 0
noauth
crtscts
local
lock
hide-password
modem
-pap
+chap
passive
lcp-echo-interval 30
lcp-echo-failure 4
noipx
Key settings explained:
- ms-dns: Primary and secondary DNS servers for clients
- -pap: Disables PAP authentication
- +chap: Enables CHAP authentication
/etc/ppp/pppoe-server-options
sudo vim /etc/ppp/pppoe-server-options
Create the file if it does not exist:
auth
require-chap
logfile /var/log/pppd.log
+ipv6
/etc/ppp/chap-secrets
sudo vim /etc/ppp/chap-secrets
User credentials format:
# client server secret IP addresses
vpnuser * SecurePass2024 *
Format: username server password allowed IPs
- username: Client connection identifier
- server: Arbitrary name for the server entry
- password: Authentication credential
- IP addresses:
*allows any IP, or specify fixed addresses
Enabling IP Forwarding
Enable packet forwarding between interfaces:
echo 1 > /proc/sys/net/ipv4/ip_forward
Verify the setting:
cat /proc/sys/net/ipv4/ip_forward
Expected output: 1
To make this persistent across reboots, edit /etc/sysctl.conf:
sudo vim /etc/sysctl.conf
Add or uncomment:
net.ipv4.ip_forward = 1
Starting the Service
First, terminate any existing PPPoE server processes:
sudo killall pppoe-server 2>/dev/null
Launch the PPPoE server with desired parameters:
sudo pppoe-server -I eth0 -L 10.20.30.1 -R 10.20.30.50 -N 10
Parameter reference:
- -I: Network interface name (use
ip addrorifconfigto identify) - -L: Server-side IP address for PPP connections
- -R: Starting IP adress for the client address pool
- -N: Number of available client addresses in the pool
In this example:
- Interface: eth0
- Server IP: 10.20.30.1
- Client pool starts at: 10.20.30.50
- Pool size: 10 addresses (10.20.30.50 - 10.20.30.59)
Configuring NAT Rules
Apply NAT masquerading to allow clients to access the internet through the server:
sudo iptables -t nat -A POSTROUTING -s 10.20.30.0/24 -o eth0 -j MASQUERADE
Replace 10.20.30.0/24 with the actual subnet and eth0 with the external interface.
Verify the NAT rule:
sudo iptables -t nat -L -n
Expected output should include:
Chain POSTROUTING (policy ACCEPT)
target prot opt source destination
MASQUERADE all -- 10.20.30.0/24 0.0.0.0/0
Verification
Server-side Interface Check
After successful startup, the server should have a ppp interface:
ppp0 Link encap:Point-to-Point Protocol
inet addr:10.20.30.1 P-t-P:10.20.30.50 Mask:255.255.255.255
UP POINTOPOINT RUNNING NOARP MULTICAST MTU:1480 Metric:1
RX packets:4820 errors:0 dropped:0 overruns:0 frame:0
TX packets:3650 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:3
RX bytes:518420 (518.4 KB) TX bytes:412350 (412.3 KB)
Client-side Interface Check
The connected client will have a ppp interface with the opposite endpoint:
ppp0 Link encap:Point-to-Point Protocol
inet addr:10.20.30.55 P-t-P:10.20.30.1 Mask:255.255.255.255
UP POINTOPOINT RUNNING NOARP MULTICAST MTU:1480 Metric:1
RX packets:1850 errors:0 dropped:0 overruns:0 frame:0
TX packets:2240 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:3
RX bytes:425680 (425.6 KB) TX bytes:389450 (389.4 KB)
Automation Script
#!/bin/bash
setup_pppoe_server() {
echo "Initializing PPPoE Server Setup"
# Check and install dependencies
if [ ! -f /etc/ppp/pppoe-server-options ]; then
echo "Installing PPPoE packages..."
sudo apt-get install -y pppoe-server pppoe
fi
# Network configuration
local wan_iface="eth0"
local lan_subnet="192.168.100"
local subnet_mask="24"
local pool_size="15"
# Stop existing service
local running_pid=$(pgrep pppoe-server)
if [ -n "$running_pid" ]; then
echo "Stopping existing PPPoE server..."
sudo killall pppoe-server
sleep 1
fi
# Start PPPoE server
echo "Starting PPPoE server on interface $wan_iface"
sudo pppoe-server -I "$wan_iface" \
-L "${lan_subnet}.1" \
-R "${lan_subnet}.100" \
-N "$pool_size"
# Configure NAT if not already set
local nat_rule=$(sudo iptables -t nat -S 2>/dev/null | grep "${lan_subnet}.0")
if [ -z "$nat_rule" ]; then
echo "Configuring NAT rules..."
sudo iptables -t nat -A POSTROUTING \
-s "${lan_subnet}.0/${subnet_mask}" \
-o "$wan_iface" \
-j MASQUERADE
else
echo "NAT rules already present"
fi
# Display current credentials
echo ""
echo "Current authentication credentials:"
sudo cat /etc/ppp/chap-secrets | tail -n 5
}
setup_pppoe_server
Running the Script
- Save the script to a file, for example
setup-pppoe.sh - Make it executable:
chmod +x setup-pppoe.sh - Execute with sudo:
sudo ./setup-pppoe.sh - For automatic startup on boot, add to
/etc/rc.localor create a systemd service
Note: After running the script initially, manually verify and adjust configuration files as needed. Re-run the script after configuration changes.