Super User is a question and answer site for computer enthusiasts and power users. 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

I have written a simple script to allow a user to manually config their IP address and DNS server. The DNS servers are changed by creating a new /etc/resolv.conf file with the lines the user has entered, for example the file could end up looking like:


however after a reboot these changes seem not to work and using the DNS fails.

I can still ping IP address but trying to ping websites fail.

Below is the complete script, let know what you think the issue could be.


# wipes any corrent set up
> /etc/network/interfaces

echo "Automatic DHCP or Manual?,(D/M) followed by [ENTER]:"
read network

if [ $network == "D" ]; then
    echo "auto lo" >> /etc/network/interfaces

    echo "iface lo inet loopback" >> /etc/network/interfaces
    echo "iface eth0 inet dhcp" >> /etc/network/interfaces
    echo "iface default inet dhcp" >> /etc/network/interfaces
    echo "Network set up!"
    exit 0

if [ $network == "M" ]; then
    echo "Enter IP address (e.g, followed by [ENTER]:"
    read address
    echo "Enter Netmask (e.g, followed by [ENTER]:"
    read mask
    echo "Enter router IP (e.g, followed by [ENTER]:"
    read router
    echo "Enter first DNS server (e.g, followed by [ENTER]:"
    read dns1
    echo "Enter second DNS server (e.g, followed by [ENTER]:"
    read dns2

    echo "auto lo" >> /etc/network/interfaces
    echo "iface lo inet loopback" >> /etc/network/interfaces

    echo "iface eth0 inet static" >> /etc/network/interfaces
    echo "  address $address" >> /etc/network/interfaces    
    echo "  netmask $mask" >> /etc/network/interfaces
    echo "  gateway $router" >> /etc/network/interfaces

    echo "iface default inet dhcp" >> /etc/network/interfaces

    > /etc/resolv.conf
    echo "nameserver $dns1" >> /etc/resolv.conf
    echo "nameserver $dns2" >> /etc/resolv.conf

    echo "Network set up!"
    exit 0


echo "ERROR: you do not enter D or M";
exit 0

The script was based on the information for manual configuration found here

When Automatic DHCP is used the /etc/resolv.conf contains:

share|improve this question
Do you have network mangler, errh, manager installed? – tink Jun 19 '13 at 19:57
@tink users will have very limited access to the system so a network manager would not be best – Zac Powell Jun 19 '13 at 20:18
I appreciate that, which is why I asked :) It just frequently interferes with attempts to manually configure things. – tink Jun 19 '13 at 20:23
Ok so you think the script 'should' work, but something is possible interfering with the manual set up? The raspbian used is pretty standard so would likely include a network manager I am just not using it – Zac Powell Jun 19 '13 at 20:26
Note that and may help you find a more specific answer – Tobias Kienzler Jun 20 '13 at 12:15

The default resolvconf package makes /etc/resolv.conf into a symlink. If you remove the symlink and create a new resolv.conf it will stick after a reboot. You are very close with the > /etc/resolv.conf line, but apparently that doesn't overwrite the symlink. I would suggest first deleting the old symlink with rm /etc/resolv.conf (or better, back it up with mv /etc/resolv.conf /etc/resolv.conf.bak) just before that line.

share|improve this answer
No luck still doesn't work as before IP addresses work so I am connected but DNS server is not being used – Zac Powell Jun 20 '13 at 12:07

You must log in to answer this question.

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