1

My Linux box currently has a network interface that allows me to connect to a network on a different subnet. I've achieved this by modifying the routing table when the network interface is brought up. The 'remote' network also has a DNS server so I want to add that to my /etc/resolv.conf file when the interface enabled.

My /etc/network/interfaces file currently has the following:

# Secondary network interface (using NAT) allow-hotplug eth1 iface eth1 inet dhcp post-up route add -net 172.16.0.0 netmask 255.255.255.0 gw 10.0.3.2 post-up echo 'Up and running...' >> /home/sysadmin/net-result.txt; date >> /home/sysadmin/net-result.txt post-up sed -i '1inameserver 172.16.0.1' /etc/resolv.conf post-down sed -i '/^nameserver 172.16.0.1/d' /etc/resolv.conf 

(The line post-up echo... is just there to prove that the commands are being run and that they have access to the file system.)

This works fine when I use ifup eth1 and ifdown eth1 from the command line to control the interface. The line nameserver 172.16.0.1 appears (and disappears) in /etc/resolv.conf as expected.

However, it's not working on system startup for some reason. The route command is being executed (because I can see the modifications in the routing table) and the /home/sysadmin/net-status.txt file is also being modified as expected, but /etc/resolv.conf does not change.

I can't work out what the problem is. Does anyone have any suggestions?

(The Linux box is actually a virtual machine, and the remote network is accessed via a VPN, but I don't think either of these details really have a bearing on the problem in this context.)

3
  • I think you can try redirecting the stdout & stderr of that command to redirect to some file to know why the resolv.conf is not getting updated on bootup. Commented Apr 4, 2013 at 8:32
  • @pradeepchhetri - I appended &> /home/sysadmin/net-up-result.txt to the post-up sed... stanza. The file time-stamp changes (so it's being modified) but the contents are empty. Commented Apr 4, 2013 at 9:07
  • Is the Linux box an ubuntu machine? The latest versions of *buntu generate resolv.conf out of thin air by default based on whatever network events they deem relevant. Commented Apr 4, 2013 at 20:39

0

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.