0% found this document useful (0 votes)
95 views

Internet Sharing in Linux

The document provides instructions for configuring IP forwarding and network address translation (NAT) on a system to enable it to function as a router. It describes enabling IP forwarding using sysctl, configuring iptables for masquerading, and an example network configuration with IP addresses, netmasks, and gateways for connected systems and interfaces. It also lists example outputs from iptables and ip_forward commands to check the configuration.

Uploaded by

jinish.K.G
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
95 views

Internet Sharing in Linux

The document provides instructions for configuring IP forwarding and network address translation (NAT) on a system to enable it to function as a router. It describes enabling IP forwarding using sysctl, configuring iptables for masquerading, and an example network configuration with IP addresses, netmasks, and gateways for connected systems and interfaces. It also lists example outputs from iptables and ip_forward commands to check the configuration.

Uploaded by

jinish.K.G
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 2

Enable IP forwarding

Run as root

sysctl -w net.ipv4.ip_forward=1

To enable it in system startup, edit the file /etc/sysctl.conf and set

net.ipv4.ip_forward = 1

iptables
Run command as root

iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE


service iptables save

Configuration
The configuration should be like this

Router

Connected to the internet provider


IP : 192.168.1.1

Internet Connected System

eth0 (LAN Card 1)

Connected to router

 IP : 192.168.1.10
 Netmask : 255.255.255.0
 Gateway : 192.168.1.1 (IP of the router)

eth1 (LAN Card 2)

Connected to the other system

 IP : 192.168.0.20 (Not the same network as the first card)


 Netmask : 255.255.255.0
 Gateway : 192.168.1.1 (IP of the router)

Second System
LAN Card connected to the first system

 IP : 192.168.0.30
 Netmask : 255.255.255.0
 Gateway : 192.168.0.20 (IP of the second Card in the first system)

Status
Some results of various commands are shown here. Check to see if it matches the result
on your system.

# iptables -t nat -L POSTROUTING


Chain POSTROUTING (policy ACCEPT)
target prot opt source destination
MASQUERADE all -- anywhere anywhere
# cat /proc/sys/net/ipv4/ip_forward
1
# iptables -L
Chain INPUT (policy ACCEPT)
target prot opt source destination

Chain FORWARD (policy ACCEPT)


target prot opt source destination

Chain OUTPUT (policy ACCEPT)


target prot opt source destination

You might also like