/etc/network/interfaces

Aus Foxwiki

Beschreibung

The file /etc/network/interfaces available in Debian and its derived distributions allows to define static and dynamic IP addresses for the interfaces, setup routing information and default gateways, masquerading network bonding and more.

The default interfaces file looks like the following:

Datei:Bild12.pngWhere auto starts the interface at boot and iface calls the network interface (in this case lo, loopback). All lines beginning with  “auto” specify the interfaces which will be enabled when running “ifup -a”, a command executed at boot.

Lines beginning with “iface” have the following syntax

iface  <interface>  <address_family>  <method>

For example

iface enp2s0 inet dhcp

The following example shows how to setup a network card using DHCP:

Setting up an interface with DHCP by editing the /etc/network/interfaces:

To add a new interface using DHCP, add the following lines:

auto <Interface>allow-hotplug <Interface>iface <Interface> inet dhcp

Datei:Bild13.pngWhere allow-hotplug will start the interface upon event detection.

Note
for IPv6 add “inet6”: iface <interface> inet6 dhcp

Where <interface> you should set your device name, eth0, enp2s0, wlp3s0, etc.

Setting up an interface with static address by editing the /etc/network/interfaces:

If instead of configuring the interface with DHCP you want to set a static IP address and gateway replace the previous instructions with the following (replace 192.168.0.8/24 and 192.168.0.1 with your correct IP addresses):auto <Interface>iface <Interface> inet staticaddress 192.168.0.1netmask 255.255.255.0gateway 192.168.0.1dns-nameservers 8.8.8.8

Datei:Bild14.pngDefining gateway and broadcast is optional.The following example shows a different configuration which runs after the network interface is enabled (up) or disabled (down). The “up” lines are executed when the device is enabled while the “down” lines when it is disabled:

auto eth0iface eth0 inet staticaddress 192.168.0.5network 192.168.0.0netmask 255.255.255.128broadcast 192.168.0.0up route add -net 192.168.0.128 netmask 255.255.255.0 gw 192.168.0.1up route add default gw 192.168.0.200down route del default gw 192.168.0.200down route del -net 192.168.0.128 netmask 255.255.255.128 gw 192.168.0.1

Datei:Bild15.png

Setting up a network card with 2 interfaces:

The following example below shows a static configuration for a network card with two interfaces:

auto eth0 eth0:1iface eth0 inet staticaddress 192.168.0.5network 192.168.0.0netmask 255.255.255.0broadcast 192.168.0.255gateway 192.168.0.1iface eth0:1 inet staticaddress 192.168.0.10network 192.168.0.0netmask 255.255.255.0

Datei:Bild16.pngAs you can see in this way you can assign multiple IP addresses to a single network interface.

Configure network bonding by editing the /etc/network/interfaces:

The following example shows my previous bonding mode 1 configuration within the /etc/network/interfaces file, I will leave interfaces with their names for easier understanding:

auto enp2s0iface enp2s0 inet manualbond-master bond0bond-primary enp2s0 wlp3s0 auto wlp3s0iface wlp3s0 inet manualbond-master bond0bond-primary enp2s0 wlp3s0wpa-ssid 'LinuxHint'wpa-bssid '14:CF:E2:2A:EF:00'wpa-psk  '972537288765'auto bond0iface bond0 inet dhcpbond-slaves nonebond-mode active-backupbond-miimon 100bond-downdelay 200bond-updelay 200

Datei:Bild17.pngA network bonding configuration with static IP instead of DHCP would have the last block like:

iface bond0 inet staticaddress 192.168.0.54netmask 255.255.255.0network 192.168.0.0gateway 192.168.0.1

Datei:Bild18.pngYou can run the following command to make sure bonding is working properly:# cat /proc/net/bonding/bond0

Datei:Bild19.png

Source of examples: How to do Linux Network Bonding

Enable logging for the file /etc/network/interfaces:

There are 3 options related to the logging:

VERBOSE
instructs log files to have detailed information.DEBUG: enable debugging when logging.SYSLOG: save logs within /var/log/syslog.

Datei:Bild20.pngPre-up commands for /etc/network/interfaces: Pre-up commands are executed before enabling the network device. If the pre-up command fails the network card activation wont take place.

Post-up instructions for /etc/network/interfaces
Post-up instructions are executed after the network interface is enabled.
Pre-down instructions for /etc/network/interfaces
Pre-down instructions are executed before disabling the network device.Post-down instructions for /etc/network/interfaces: Post-down instructions are executed after the network interface is disabled.

Pre-up, pre-down, post-up and post-down flags are conditional, if they ail the network device won’t get enabled or won’t be properly marked as disabled.

For example, the instruction:

pre-up /usr/local/sbin/iptables

Will run the firewall before the network interface gets enabled, if iptables fails to start the network interface wont turn on.

Quelle: https://linuxhint.com/debian_etc_network_interfaces/




TMP

Persistente Routen

Dauerhafte (persistente) statische Routen werden in /etc/network/interfaces eingetragen

#--------------------------------------------#
# Setup the loopback network interface (lo0) #
#--------------------------------------------#
auto lo
iface lo inet loopback

#--------------------------------------------#
# Setup eth0 - connected to private LAN/VLAN #
#--------------------------------------------# 
auto eth0
allow-hotplug eth0
iface eth0 inet static
       address 10.70.201.5
       netmask 255.255.255.192
       ### add persistent route command ###
       post-up route add -net 10.0.0.0 netmask 255.0.0.0 gw 10.70.201.6
#----------------------------------------#
# Setup eth1 - connected to the Internet #
#----------------------------------------#
auto eth1
allow-hotplug eth1
iface eth1 inet static
       address 205.153.203.98
       netmask 255.255.255.248
       ### default gateway ###
       gateway 205.153.203.97
# service networking restart

Links

Intern

Weblinks

  1. https://www.cyberciti.biz/tips/configuring-static-routes-in-debian-or-red-hat-linux-systems.html