Network configuration on Raspbian

Network configuration on Raspbian

By default Raspbian is set up for DHCP which is quite fine in many cases, but less fine if you want to use it as a server or other applications where a known static IP address is important. One option is to use a DHCP reservation on a DHCP server, but if you do not have one or want to use one, you could just setup a static address in the configuration files in Raspbian

To view the current IP address use the  ifconfig command.

pi@raspberrypi ~ $ ifconfig
eth0      Link encap:Ethernet  HWaddr b8:27:eb:9c:62:17
          inet addr:  Bcast:  Mask:
          RX packets:1543 errors:0 dropped:0 overruns:0 frame:0
          TX packets:1079 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:116617 (113.8 KiB)  TX bytes:125062 (122.1 KiB)

lo        Link encap:Local Loopback
          inet addr:  Mask:
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

pi@raspberrypi ~ $

The configuration is stored in /etc/network/interfaces which can be opened with a text editor

sudo nano /etc/network/interfaces

My Raspberry Pi only have one interface, so it is the eth0 interface. By default, it is setup for DHCP.

iface eth0 inet dhcp

To configure a static IPv4 address up changed the above line to the following. Replace the addresses with those that needed in your network

iface eth0 inet static

DNS servers are configured in the file /etc/resolv.conf.  If the PI has received a DHCP assigned address, the DNS servers that the DHCP server provides, remains in the file even when the configuration is changed to static.

These are TDC DNS servers.