After spending time on Ubuntu DNS, you may encounter network issues. This article introduces solutions. After a fresh Ubuntu install, even if you set IP and gateway via GUI, you may not be able to go online.
A friend suggested trying command-line settings. It actually worked. Here is how:
1. Check connectivity with ping — initially showed unreachable.
2. Set IP: sudo ifconfig eth0 133.133.133.190 netmask 255.255.255.0
3. Set gateway: sudo route add default gw 133.133.133.40
4. Now you can ping the gateway successfully.
5. Set DNS: edit /etc/resolv.conf and add:
nameserver your-dns-address-1
nameserver your-dns-address-2. After reboot, the IP seems to change again.
1. Set Ubuntu IP Using Commands
1. Set IP: sudo ifconfig eth0 203.171.239.155 netmask 255.255.255.224
2. Set gateway: sudo route add default gw 203.171.239.129
3. Set DNS: edit /etc/resolv.conf and add nameserver entries. However, IP seems lost on next reboot.
2. Modify System Configuration Files Directly
The Ubuntu network config file is: /etc/network/interfaces
Open /etc/network/interfaces to set DHCP or static IP. Use auto eth0 to auto-load on boot.
1. Configure NIC with DHCP
Edit /etc/network/interfaces and replace the eth0 section:
- # The primary network interface – use DHCP to find our address
- auto eth0
- iface eth0 inet dhcp
Apply with sudo /etc/init.d/networking restart or sudo dhclient eth0.
2. Configure Static IP
Edit /etc/network/interfaces and replace the eth0 section:interface
- auto eth0
- iface eth0 inet static
- address 192.168.3.90
- gateway 192.168.3.1
- netmask 255.255.255.0
- #network 192.168.3.0
- #broadcast 192.168.3.255
Replace IP info with your own. Apply with sudo /etc/init.d/networking restart.
3. Set Second IP (Virtual IP)
Edit /etc/network/interfaces and add:
- auto eth0:1
- iface eth0:1 inet static
- address 192.168.1.60
- netmask 255.255.255.0
- network x.x.x.x
- broadcast x.x.x.x
- gateway x.x.x.x
Fill in address, netmask, etc. Apply with sudo /etc/init.d/networking restart.
4. Set Hostname
View: sudo /bin/hostname
Set: sudo /bin/hostname newname
On boot, the hostname is read from /etc/hostname.
For more info, visit here.
5. Configure Ubuntu DNS
Add entries to /etc/hosts for static queries. Configure /etc/resolv.conf for DNS server queries. Assuming the Ubuntu DNS server IP is 192.168.3.2, the /etc/resolv.conf file content should be:
search test.com
nameserver 192.168.3.2
/etc/network/interfaces
Set DHCP or static IP. Use auto eth0 for boot-time loading.
1. Configure NIC with DHCP
Edit /etc/network/interfaces and replace eth0 section:
- # The primary network interface – use DHCP to find our address
- auto eth0
- iface eth0 inet dhcp
Apply with sudo /etc/init.d/networking restart or sudo dhclient eth0.
2. Configure Static IP
Edit /etc/network/interfaces:
Replace eth0 section with: # The primary network interface
- auto eth0
- iface eth0 inet static
- address 192.168.3.90
- gateway 192.168.3.1
- netmask 255.255.255.0
- #network 192.168.3.0
- #broadcast 192.168.3.255
Replace IP info with your own. Apply with sudo /etc/init.d/networking restart.
3. Set Second IP (Virtual IP)
Edit /etc/network/interfaces and add:
- auto eth0:1
- iface eth0:1 inet static
- address 192.168.1.60
- netmask 255.255.255.0
- network x.x.x.x
- broadcast x.x.x.x
- gateway x.x.x.x
Fill in address, netmask, etc. Apply with sudo /etc/init.d/networking restart.
4. Set Hostname
View: sudo /bin/hostname
Set: sudo /bin/hostname newname
Hostname is read from /etc/hostname on boot. More info: visit here.
5. Configure Ubuntu DNS
Add entries to /etc/hosts for static queries. Configure /etc/resolv.conf for DNS server queries. Assuming the Ubuntu DNS server IP is 192.168.3.2, the /etc/resolv.conf file content should be:
- search test.com
- nameserver 192.168.3.2
Solving Ubuntu DNS reset on reboot. Delete the old DNS entries and add static DNS servers. However, this resets on reboot and needs to be reconfigured each time.
Backup first: sudo cp /etc/resolv.conf /etc/resolv.conf.bak. Then edit with sudo gvim /etc/dhcp3/dhclient.conf and add at the end: prepend domain-name-servers 208.67.222.222,208.67.220.220; # Fill in these servers according to your own DNS settings.