Guide- Setting up a Static IP and DNS
Setting up a Static IP and fixing DNS issues
Some use cases require that you keep a static IP address, and dont work well with hostnames. This guide will show you how to set up a static IP address and to fix up DNS issues that are commonly caused by that.
You'll need be logged in to your device and before you start changing anything, you'll need to collect some information about your current network configuration. In order to get the information, you can use either of the following commands:
You'll also need to get the Gateway:
You'll get output similar to the following. Note down the Gateway as well as the Subnet Number.
You'll need to modify the network interfaces file in order to set a static IP address.
Insert your password and it should open up to the text editor interface you've become quite familiar with. You'll need to comment out the last line, and add your own settings. Mine are shown below:
auto eth0 iface eth0 inet static address 192.168.1.128 netmask 255.255.255.0 gateway 192.168.1.1 dns-nameservers 188.8.131.52 184.108.40.206
Address is what you'd like your IP address to be. Normally it's in the range of 192.168.1.xxx where xxx is a number between 1-254. You can use a Network scanning app, like Fing, to see what IP addresses are occupied.
I dont know enough to know exactly what a netmask is, however, if your IP address had a "/24" after it, as shown above, the netmask would be 255.255.255.0
The gateway is what was shown in the command "ip route", write down its value here. In my case it was 192.168.1.1
The DNS nameserver simply tells your computer where to go to see what human readable URL corresponds to what IP address. I personally use Googles Nameservers, you can use that, or you can select one from the handy list here.
Fill in the details, then save and exit the editor. Restart your device using the following command:
Wait a minute or so for it to boot up. If you want to see if its on the network with the new IP address address before trying to SSH into it, you can do so using a network scanning up, like FING. You could do a new scan and you will see your board occupying the new IP address you set.
SSH in, using either your newly set IP address or your Hostname. Now its time to check if WAN (internet) access still works.
We are going to ping googles DNS servers (any IP address SHOULD work) for this.
[email protected]:~$ ping 220.127.116.11 PING 18.104.22.168 (22.214.171.124) 56(84) bytes of data. 64 bytes from 126.96.36.199: icmp_seq=1 ttl=57 time=19.8 ms 64 bytes from 188.8.131.52: icmp_seq=2 ttl=57 time=11.9 ms 64 bytes from 184.108.40.206: icmp_seq=3 ttl=57 time=11.3 ms 64 bytes from 220.127.116.11: icmp_seq=4 ttl=57 time=12.3 ms 64 bytes from 18.104.22.168: icmp_seq=5 ttl=57 time=12.4 ms 64 bytes from 22.214.171.124: icmp_seq=6 ttl=57 time=14.9 ms ^C --- 126.96.36.199 ping statistics --- 6 packets transmitted, 6 received, 0% packet loss, time 5007ms rtt min/avg/max/mdev = 11.394/13.836/19.891/2.927 ms
The "^C" key shown there is simply holding down Control and pressing C. This send the program a "SIGINT" which asks the program to "end" or "stop".
This command shows that we can communicate with Googles DNS servers, which means that the internet is working. To see confirm that the DNS service is working, redo the ping command, but use a text URL instead:
[email protected]:~$ ping www.pine64.org PING www.pine64.org (188.8.131.52) 56(84) bytes of data. 64 bytes from 184.108.40.206: icmp_seq=1 ttl=51 time=106 ms 64 bytes from 220.127.116.11: icmp_seq=2 ttl=51 time=108 ms 64 bytes from 18.104.22.168: icmp_seq=3 ttl=51 time=109 ms 64 bytes from 22.214.171.124: icmp_seq=4 ttl=51 time=115 ms 64 bytes from 126.96.36.199: icmp_seq=5 ttl=51 time=109 ms 64 bytes from 188.8.131.52: icmp_seq=6 ttl=51 time=107 ms ^C --- www.pine64.org ping statistics --- 6 packets transmitted, 6 received, 0% packet loss, time 5007ms rtt min/avg/max/mdev = 106.631/109.628/115.740/2.966 ms [email protected]:~$
You have now successfully assigned a static IP address to your board, and ensured that the internet is accessible and that the DNS service is working properly.