1

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?

1
  • 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, 2011 at 1:33

1 Answer 1

4

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


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .