Configuring Linux static IP

From PedrosBrainDump

How to configure static IP on Linux distros

I'll not cover gui network managers, only file stuff.

Debian

File : /etc/network/interfaces

Configuration:

auto NETWORK-INTERFACE
iface NETWORK-INTERFACE inet static
    address xxx.xxx.xxx.xxx
    gatway xxx.xxx.xxx.xxx
    netmask xxx.xxx.xxx.xxx

Let's suppose that you want to configure the interface ens18 with the ip 192.168.0.100 netmask 255.255.255.0 and gateway 192.168.0.1:

auto ens18
iface ens18 inet static
    address 192.168.0.100
    gatway 255.255.255.0
    netmask 192.168.0.1

Oracle Linux

file : /etc/sysconfig/network-scripts/ifcfg-interface-name

NAME=interface-name
DEVICE=interface-name
ONBOOT=yes
NETBOOT=yes
UUID=auto-filled
IPV6INIT=yes
TYPE=Ethernet
BOOTPROTO=none
IPADDR=xxx.xxx.xxx.xxx
NETMASK=xxx.xxx.xxx.xxx
GATEWAY=xxx.xxx.xxx.xxx
PROXY_METHOD=none
BROWSER_ONLY=no
PREFIX=24
DEFROUTE=yes
IPV4_FAILURE_FATAL=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no

Let's suppose that you want to configure the interface eth0 with the ip 192.168.0.100 netmask 255.255.255.0 and gateway 192.168.0.1:

file : /etc/sysconfig/network-scripts/ifcfg-eth0

NAME=eth0
DEVICE=eth0
ONBOOT=yes
NETBOOT=yes
UUID=auto-filled
IPV6INIT=yes
TYPE=Ethernet
BOOTPROTO=none
IPADDR=192.168.0.100
NETMASK=255.255.255.0
GATEWAY=192.168.0.1
PROXY_METHOD=none
BROWSER_ONLY=no
PREFIX=24
DEFROUTE=yes
IPV4_FAILURE_FATAL=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no