Software >> OS >> Unix >> Linux >> Debian >> How to configure static or dynamic IP on network interfaces


Debian 11


## interface settings are set in /etc/network/interfaces or included files in /etc/network/interfaces.d/

## Example 1, configure every interface in /etc/network/interfaces

vi /etc/network/interfaces

/etc/network/interfaces
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).

source /etc/network/interfaces.d/*

# The loopback network interface
auto lo
iface lo inet loopback
#
auto enp0s3
iface enp0s3 inet dhcp
#
auto enp0s8
iface enp0s8 inet dhcp
#
auto enp0s9
iface enp0s9 inet static
   address 192.168.0.101
   netmask 255.255.255.0

## The statement auto means that the interfaces will be brough up when ifup -a is executed
## e.g. the networking service is started.
## Other options for static
##    address [address]
##    netmask [mask]
##    broadcast [broadcast_address]
##    metric [metric] (Routing metric for default gateway, integer value)
##    gateway [address] (Default gateway)
##    pointopoint [address] (Address of other end point)
##    hwaddress [macaddress|random]
##    mtu [size]
##    scope  [global|link]  (Address  validity  scope)


## restart the networking service

systemctl restart networking


## Example 2, configure some interface in /etc/network/interfaces
## and some in individual interface files in /etc/network/interfaces.d/

vi /etc/network/interfaces

/etc/network/interfaces
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).

source /etc/network/interfaces.d/*

# The loopback network interface
auto lo
iface lo inet loopback
#
auto enp0s3
iface enp0s3 inet dhcp


vi /etc/network/interfaces.d/enp0s8

/etc/network/interfaces.d/enp0s8
auto enp0s8
iface enp0s8 inet dhcp


vi /etc/network/interfaces.d/enp0s9

 

/etc/network/interfaces.d/enp0s9
auto enp0s9
iface enp0s9 inet static
   address 192.168.0.101
   netmask 255.255.255.0


systemctl restart networking