dirtyb15 wrote:Thanks for the reply. How do i manually set the IP address for the wired adapter that is sharing the connection?
sudo ifconfig eth0 192.168.1.2 up
sudo /etc/init.d/networking restart
Ubuntu Internet Gateway Method (iptables)
You will need two network cards in the gateway computer, or a PPP interface and a network card. One network card (or PPP interface) connects to the Internet. We will call this card eth0. The other card connects to your internal network. We will call this eth1. It is also possible to do ICS with a single network card. In this case, use eth0 for the Internet and eth0:0 for the internal network.
Internet <<==>> eth0 <> Ubuntu gateway <> eth1 <<==>> Client PC
Internet <<==>> ppp0 <> Ubuntu gateway <> eth1 <<==>> Client PC
Internet <<==>> eth0 <> Ubuntu gateway <> eth0:0 <<==>> Client PC
Gateway set up
The following example will focus on the most common gateway setup: an Ubuntu computer with two wired network adapters (eth0 and eth1) hosting ICS to a static internal network configured for the 192.168.0.x subnet.
For this example, eth0 is used to represent the network card connected to the Internet, and eth1 represents the network card connected to a client PC. You can replace eth0 and eth1 as needed for your situation. Also, any private IP subnet can be used for the internal network IP addresses.
eth0 = the network adapter with internet (external or WAN).
eth1 = the network adapter to which a second computer is attached (internal or LAN).
192.168.0.x = IP subnet for eth1
Your setup may be different. If so, make sure to change them accordingly in the following commands.
Configure internal network card
Configure your internal network card (eth1) for static IP like so:
sudo ip addr add 192.168.0.1/24 dev eth1
The external and internal network cards cannot be on the same subnet.
Configure iptables for NAT translation so that packets can be correctly routed through the Ubuntu gateway.
sudo iptables -A FORWARD -o eth0 -i eth1 -s 192.168.0.0/24 -m conntrack --ctstate NEW -j ACCEPT
sudo iptables -A FORWARD -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT
sudo iptables -t nat -F POSTROUTING
sudo iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
The first rule allows forwarded packets (initial ones). The second rule allows forwarding of established connection packets (and those related to ones that started). The third rule does the NAT.
IPtables settings need to be set-up at each boot (they are not saved automatically), with the following commands:
Save the iptables:
sudo iptables-save | sudo tee /etc/iptables.sav
Edit /etc/rc.local and add the following lines before the "exit 0" line:
iptables-restore < /etc/iptables.sav
Configure the gateway for routing between two interfaces by enabling IP forwarding:
sudo sh -c "echo 1 > /proc/sys/net/ipv4/ip_forward"
Edit /etc/sysctl.conf, and (up to 10.04) add these lines:
The /etc/sysctl.conf edit is required because of the following bug in Hardy and later releases: Launchpad Bug Report
From 10.10 onwards, it suffices to edit /etc/sysctl.conf and uncomment:
... so that it reads:
Client set up
Any OS can connect to the Internet as an ICS client as long as networking has been configured correctly. The following example will focus on how to set up an Ubuntu ICS client. For this example, it is assumed that the client is connected to an Ubuntu gateway, which has been configured to share ICS on the 192.168.0.x subnet according to the gateway set up outlined above.
For this example, eth0 is the network card on the client which is connected (by crossover cable) to eth1 on the Ubuntu gateway. You can replace eth0 as needed for your situation. Also, any private IP subnet can be used for the internal network IP address, as long as it matches the subnet on the gateway.
sudo /etc/init.d/networking stop
Give the client a static IP address
sudo ip addr add 192.168.0.100/24 dev eth0
This IP address can be anything within the gateway's private IP range.
sudo ip route add default via 192.168.0.1
This address should match the IP address on the gateway's internal network card (eth1 in the above example).
Configure DNS servers
Unless your ICS gateway can also perform DNS, you must manually configure the client with your ISP DNS servers. If you do not know your ISP's DNS servers, you can use OpenDNS servers instead.
Backup your current /etc/resolve.conf file:
sudo cp /etc/resolv.conf /etc/resolv.conf.backup
Open /etc/dhcp3/dhclient.conf with your favorite text editor:
sudo nano /etc/dhcp3/dhclient.conf
Search for the line that starts "prepend domain-name-servers", and change it to look like this:
prepend domain-name-servers 22.214.171.124,126.96.36.199;
188.8.131.52 and 184.108.40.206 are OpenDNS DNS servers. If you wish to use your ISP's DNS servers, use them here instead of the OpenDNS servers.
sudo /etc/init.d/networking restart
Once this is finished, your client will now have access to the Internet via ICS. Please direct any questions/comments to the Internet Connection Sharing Documentation thread.
Users browsing this forum: No registered users and 4 guests