Raspberry Pi (or Ubuntu) IP Address Setting

IP Address Settings Static:

# /etc/network/interfaces
iface eth0 inet static
address a.b.c.d
netmask 255.255.255.0
gateway 192.168.0.1

IP Address Settings DHCP:

# /etc/network/interfaces
iface eth0 inet manual

Or

# /etc/network/interfaces
iface eth0 inet dhcp

Starting Ubuntu 18.04 LTS using netplan:
/etc/netplan/01-network-manager-all.yaml
network:
  version: 2
  renderer: networkd
  ethernets:
    enp1s0:
      dhcp4: no
      addresses: [192.168.1.222/24]
      # gateway4: 192.168.1.1 --deprecated
routes:
- to: default
via: 192.168.1.1

      nameservers:
        addresses: [8.8.8.8,8.8.4.4]

apply the configuration:
netplan apply

or using NetworkManager

network:
  version: 2
  renderer: NetworkManager

and use command below to set ip:

nmcli con mod "Wired connection 1" ipv4.address 1.2.3.4/24 ipv4.gateway 1.2.3.4 ipv4.dns 1.2.3.4 ipv4.method manual
# write above command in one single line

Nameserver:
a) Ubuntu versions < 14.04

# /etc/resolv.conf
nameserver 8.8.8.8
nameserver 8.8.4.4

b) Ubuntu versions >= 14.04

# /etc/network/interfaces
dns-nameservers 8.8.8.8

Note: For raspbian, when using static ip, you must disable DHCP service in /etc/dhcpcd.conf, add this line:

denyinterfaces eth0

Update 13 Oct 18, raspbian now use dhcp5 so you need to edit/etc/dhcpcd.conf

# Example static IP configuration:
#interface eth0
#static ip_address=192.168.0.10/24
#static ip6_address=fd51:42f8:caae:d92e::ff/64
#static routers=192.168.0.1
#static domain_name_servers=192.168.0.1 8.8.8.8 fd51:42f8:caae:d92e::1

Leave a Reply

Your email address will not be published. Required fields are marked *