Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. 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

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 netmask gw
        post-up echo 'Up and running...' >> /home/sysadmin/net-result.txt; date >> /home/sysadmin/net-result.txt
        post-up sed -i '1inameserver' /etc/resolv.conf
        post-down sed -i '/^nameserver' /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 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.)

share|improve this question
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. – pradeepchhetri Apr 4 '13 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. – LSW Apr 4 '13 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. – tink Apr 4 '13 at 20:39

Your Answer


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

Browse other questions tagged or ask your own question.