Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have two NICs.

Here's my /etc/network/interfaces:

auto eth0
iface eth0 inet dhcp    //for internet

auto eth1
iface eth1 inet static   //for lan
address 20.X.X.X.X
broadcast 20.X.X.X.255
gateway 20.X.X.1
  1. Which gateway is default? How do I route gateway to default gateway?

  2. When I run networking restart, resolv.conf domain name server is replaced with the DNS server of the internet, how do I configure resolv.conf?

share|improve this question
I edited your question. I am a native English speaker, but I'm not clairvoyant. If I got the meaning of anything wrong, let me know. I had the hardest time understanding question #2, so it may be wrong. I took my best shot at answering your question for IPv4. I'll add the IPv6 part later. – Azendale Jul 26 '11 at 1:33

If I understand what you're trying to do, you need to install a couple of things:

sudo apt-get install dhcp3-server resolvconf #also possibly 'radvd'

Enabling traffic through you machine (IPv4):
Ok, now let's change a setting:

sudo nano /etc/sysctl.conf

Delete the # from the start of the line #net.ipv4.ip_forward=1 and press Ctrl x, then y to save.

Run sudo sysctl -p.

Set address for LAN interface (IPv4):
Unless you are 'Computer Sciences Corporation', you should not be using 20.x.x.x addresses. You could use any of the following private addresses ranges instead: 10.x.x.x, 192.168.x.x, or the range – (aka or with netmask Run

sudo nano /etc/network/interfaces

Delete the gateway line. This computer is the gateway for the connection, so you do not set a gateway for this interface. Other computers will have this computer's address as their gateway. Change the address line to address Change the broadcast line to broadcast Press Ctrl x, then y to save.

Set DNS server (IPv4 and/or IPv6):

sudo nano /etc/resolvconf/resolv.conf.d/head

(ignore the scary warning. /etc/resolv.conf is autogenerated, so the warning is in the /etc/resolvconf/resolv.conf.d/head file so it will get put at the top of /etc/resolv.conf when /etc/resolv.conf is generated.) To the end of the file, add

 nameserver <ip_of_nameserver>

Press Ctrl x and answer yes to saving the file. To finish up, regenerate /etc/resolv.conf so the changes are applied right now:

 sudo resolvconf -u

Set up NAT (IPv4)(shudder):
Enable UFW:

sudo ufw enable

Make a persistent NAT rule that is restored at boot by UFW:

sudo nano /etc/ufw/before.rules

Add the line -A POSTROUTING -o ppp0 -j MASQUERADE after the line *nat. Press Ctrl x, then y to save.

Give out addresses (IPv4):
Let's edit some files:

sudo nano /etc/dhcp3/dhcpd.conf /etc/default/dhcp3-server

To the first file, add the following:

subnet netmask {
  option routers;
  option domain-name-servers <dns_server>;

Press Ctrl x, then y to save. In the next file, edit the line INTERFACES="" to say INTERFACES="eth1". Press Ctrl x, then y to save. To start the address handing out daemon, run

sudo /etc/init.d/dhcp3-server start

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.