Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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:

nameserver 12.34.56.78
nameserver 12.34.56.79

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.

#!/bin/bash

# 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
fi

if [ $network == "M" ]; then
    echo "Enter IP address (e.g 192.168.0.7), followed by [ENTER]:"
    read address
    echo "Enter Netmask (e.g 255.255.255.0, followed by [ENTER]:"
    read mask
    echo "Enter router IP (e.g 192.168.0.1), followed by [ENTER]:"
    read router
    echo "Enter first DNS server (e.g 8.8.8.8), followed by [ENTER]:"
    read dns1
    echo "Enter second DNS server (e.g 8.8.8.8), 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

fi

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

The script was based on the information for manual configuration found here http://wiki.debian.org/NetworkConfiguration

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

domain zyxel.com
search zyxel.com
nameserver 192.168.1.1
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 raspberrypi.stackexchange.com and unix.stackexchange.com may help you find a more specific answer –  Tobias Kienzler Jun 20 '13 at 12:15
show 1 more comment

1 Answer

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
add comment

Your Answer

 
discard

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.