Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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.)

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. –  Lorax 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
add comment

Your Answer

 
discard

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

Browse other questions tagged or ask your own question.