Nov 10, 2018

Example /etc/network/interfaces for Ubuntu

# The loopback network interface
auto lo
iface lo inet loopback

# The primary network interface
#auto em1
#iface em1 inet dhcp

auto em2
iface em2 inet static
    address 192.168.0.40
    netmask 255.255.254.0
    gateway 192.168.1.1
    dns-nameservers 8.8.8.8 8.8.4.4

# ifdown em2 && ifup em2
or
# service networking restart

to take effect.

Another example:

/29 subnet, 5 usable IPs

Your subnet is 10.0.0.0/29 and you have the following network settings (get from your network administrator if you are not sure):
Network: 10.0.0.0/29
Usable IPs: 10.0.0.2 - 10.0.0.6
Gateway: 10.0.0.1
Subnet Mask: 255.255.255.248
Broadcast Address: 10.0.0.7
Your /etc/network/interfaces would look like:
# The loopback network interface
auto lo                          
iface lo inet loopback

# The primary network interface
auto eth0
iface eth0 inet static
        address 10.0.0.2
        netmask 255.255.255.248
        gateway 10.0.0.1
        broadcast 10.0.0.7
        up ip address add 10.0.0.3 dev eth0
        up ip address add 10.0.0.4 dev eth0
        up ip address add 10.0.0.5 dev eth0
        up ip address add 10.0.0.6 dev eth0