Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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
netmask 255.255.255.0
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
add comment

1 Answer 1

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 172.16.0.0 – 172.31.255.255 (aka 172.16.0.0/12 or 172.16.0.0 with netmask 255.240.0.0). 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 10.0.0.1. Change the broadcast line to broadcast 10.0.0.255. Press Ctrl x, then y to save.


Set DNS server (IPv4 and/or IPv6):
Run

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 10.0.0.0 netmask 255.255.255.0 {
  range 10.0.0.2 10.0.0.254;
  option routers 10.0.0.1;
  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
add comment

Your Answer

 
discard

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.