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.)
&> /home/sysadmin/net-up-result.txtto thepost-up sed...stanza. The file time-stamp changes (so it's being modified) but the contents are empty.