Linux/Netzwerk/Konfiguration: Unterschied zwischen den Versionen

Aus Foxwiki
Keine Bearbeitungszusammenfassung
Zeile 1: Zeile 1:


= Netzwerkkonfiguration =
== Netzwerkkonfiguration ==
{| class="wikitable sortable options"
{| class="wikitable sortable options"
|-
|-
Zeile 21: Zeile 21:
|}
|}


== 5.1. Die elementare Netzwerkinfrastruktur ==
=== Die elementare Netzwerkinfrastruktur ===
Lassen Sie uns einen Blick auf die elementare Netzwerkinfrastruktur eines modernen Debian-Systems werfen:
Lassen Sie uns einen Blick auf die elementare Netzwerkinfrastruktur eines modernen Debian-Systems werfen:


Zeile 209: Zeile 209:




=== 5.1.1. Die Auflösung des Rechnernamens ===
==== Die Auflösung des Rechnernamens ====
Die Auflösung des Rechnernamens (hostname) wird derzeit auch durch den [https://de.wikipedia.org/wiki/Name_Service_Switch NSS-(Name-Service-Switch-)]Mechanismus unterstützt. Die Auflösung läuft wie folgt ab:# Die "<tt>/etc/nsswitch.conf</tt>"-Datei mit Einträgen wie "<tt>hosts: files dns</tt>" bestimmt die Reihenfolge der Rechnernamenauflösung. (Dies ersetzt die alte Funktionalität der "<tt>order</tt>"-Einträge in "<tt>/etc/host.conf</tt>".)
Die Auflösung des Rechnernamens (hostname) wird derzeit auch durch den [https://de.wikipedia.org/wiki/Name_Service_Switch NSS-(Name-Service-Switch-)]Mechanismus unterstützt. Die Auflösung läuft wie folgt ab:# Die "<tt>/etc/nsswitch.conf</tt>"-Datei mit Einträgen wie "<tt>hosts: files dns</tt>" bestimmt die Reihenfolge der Rechnernamenauflösung. (Dies ersetzt die alte Funktionalität der "<tt>order</tt>"-Einträge in "<tt>/etc/host.conf</tt>".)
# Als erstes wird in diesem Beispiel die <tt>files</tt>-Methode aufgerufen. Wenn der Rechnername in der "<tt>/etc/hosts</tt>"-Datei gefunden wird, werden alle gültigen Adressen für den Rechner ausgegeben und die Abfrage wird beendet. (Die "<tt>/etc/host.conf</tt>"-Datei enthält "<tt>multi on</tt>".)
# Als erstes wird in diesem Beispiel die <tt>files</tt>-Methode aufgerufen. Wenn der Rechnername in der "<tt>/etc/hosts</tt>"-Datei gefunden wird, werden alle gültigen Adressen für den Rechner ausgegeben und die Abfrage wird beendet. (Die "<tt>/etc/host.conf</tt>"-Datei enthält "<tt>multi on</tt>".)
Zeile 216: Zeile 216:
Die "<tt>/etc/hosts</tt>"-Datei sieht zum Beispiel so aus:
Die "<tt>/etc/hosts</tt>"-Datei sieht zum Beispiel so aus:


127.0.0.1 localhost
127.0.0.1 localhost
127.0.1.1 ''host_name''
127.0.1.1 ''host_name''


<nowiki># The following lines are desirable for IPv6 capable hosts</nowiki>
# The following lines are desirable for IPv6 capable hosts
::1 localhost ip6-localhost ip6-loopback
::1 localhost ip6-localhost ip6-loopback
ff02::1 ip6-allnodes
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
ff02::2 ip6-allrouters


Jede Zeile beginnt mit einer [https://de.wikipedia.org/wiki/IP-Adresse IP-Addresse] und dahinter steht jeweils der zugeordnete [https://de.wikipedia.org/wiki/Hostname Rechnername].
Jede Zeile beginnt mit einer [https://de.wikipedia.org/wiki/IP-Adresse IP-Addresse] und dahinter steht jeweils der zugeordnete [https://de.wikipedia.org/wiki/Hostname Rechnername].
Zeile 236: Zeile 236:
Die Datei "<tt>/etc/resolv.conf</tt>" ist eine statische Datei, falls das Paket <tt>resolvconf</tt> nicht installiert ist. Falls das Paket installiert ist, ist dies ein symbolischer Link. In beiden Fällen enthält es Informationen zur Initialisierung der Namensauflösungs-Routinen. Wenn das DNS zum Beispiel über die IP "<tt>192.168.11.1</tt>" erreichbar ist, enthält sie Folgendes:
Die Datei "<tt>/etc/resolv.conf</tt>" ist eine statische Datei, falls das Paket <tt>resolvconf</tt> nicht installiert ist. Falls das Paket installiert ist, ist dies ein symbolischer Link. In beiden Fällen enthält es Informationen zur Initialisierung der Namensauflösungs-Routinen. Wenn das DNS zum Beispiel über die IP "<tt>192.168.11.1</tt>" erreichbar ist, enthält sie Folgendes:


nameserver 192.168.11.1
nameserver 192.168.11.1


Das <tt>resolvconf</tt>-Paket macht "<tt>/etc/resolv.conf</tt>" zu einem symbolischen Link und verwaltet ihren Inhalt automatisch über die Hook-Skripte.
Das <tt>resolvconf</tt>-Paket macht "<tt>/etc/resolv.conf</tt>" zu einem symbolischen Link und verwaltet ihren Inhalt automatisch über die Hook-Skripte.
Zeile 259: Zeile 259:
|}
|}


=== 5.1.2. Der Netzwerkschnittstellenname ===
==== Der Netzwerkschnittstellenname ====
[https://de.wikipedia.org/wiki/Systemd Systemd] verwendet "[https://www.freedesktop.org/wiki/Software/systemd/PredictableNetworkInterfaceNames/ verlässlich vorhersagbare Namen (Predictable Network Interface Names)]" wie "<tt>enp0s25</tt>".
[https://de.wikipedia.org/wiki/Systemd Systemd] verwendet "[https://www.freedesktop.org/wiki/Software/systemd/PredictableNetworkInterfaceNames/ verlässlich vorhersagbare Namen (Predictable Network Interface Names)]" wie "<tt>enp0s25</tt>".




=== 5.1.3. Der Netzwerkadressbereich für das LAN ===
==== Der Netzwerkadressbereich für das LAN ====
Wir wollen uns an die IPv4 32-Bit-Adressbereiche erinnern, die durch die [http://tools.ietf.org/html/rfc1918 rfc1918] für jede Klasse zur Verwendung in [https://de.wikipedia.org/wiki/Local_Area_Network Local Area Networks (LANs)] reserviert sind. Diese Adressen werden bestimmt nicht mit irgendwelchen Adressen im Internet kollidieren.
Wir wollen uns an die IPv4 32-Bit-Adressbereiche erinnern, die durch die [http://tools.ietf.org/html/rfc1918 rfc1918] für jede Klasse zur Verwendung in [https://de.wikipedia.org/wiki/Local_Area_Network Local Area Networks (LANs)] reserviert sind. Diese Adressen werden bestimmt nicht mit irgendwelchen Adressen im Internet kollidieren.


Zeile 274: Zeile 274:
|-
|-
|}
|}
'''Tabelle 5.2. Liste der Netzwerkadressbereiche'''
 
; Liste der Netzwerkadressbereiche


{| class="wikitable sortable options"
{| class="wikitable sortable options"
Zeile 314: Zeile 315:
|}
|}


=== 5.1.4. Unterstützung für Netzwerkgeräte ===
==== Unterstützung für Netzwerkgeräte ====
Der größte Teil verfügbarer Netzwerk-Hardware wird durch das Debian-System unterstützt; es gibt einige Geräte, die laut [https://www.debian.org/social_contract#guidelines DFSG] nicht-freie Firmware für den Betrieb erfordern. Lesen Sie dazu [https://www.debian.org/doc/manuals/debian-reference/ch09.de.html#_hardware_drivers_and_firmware Abschnitt 9.10.5, „Hardware-Treiber und Firmware“].
Der größte Teil verfügbarer Netzwerk-Hardware wird durch das Debian-System unterstützt; es gibt einige Geräte, die laut [https://www.debian.org/social_contract#guidelines DFSG] nicht-freie Firmware für den Betrieb erfordern. Lesen Sie dazu [https://www.debian.org/doc/manuals/debian-reference/ch09.de.html#_hardware_drivers_and_firmware Abschnitt 9.10.5, „Hardware-Treiber und Firmware“].




== 5.2. Moderne Netzwerkkonfiguration für Arbeitsplatzsysteme ==
=== Moderne Netzwerkkonfiguration für Arbeitsplatzsysteme ===
Auf modernen Debian-Desktop-Systemen mit <tt>systemd</tt> erfolgt die Initialisierung von Netzwerkschnittstellen für die Loopback-Schnittstelle <tt>lo</tt> typischerweise durch "<tt>networking.service</tt>" und für andere Schnittstellen durch "<tt>NetworkManager.service</tt>".
Auf modernen Debian-Desktop-Systemen mit <tt>systemd</tt> erfolgt die Initialisierung von Netzwerkschnittstellen für die Loopback-Schnittstelle <tt>lo</tt> typischerweise durch "<tt>networking.service</tt>" und für andere Schnittstellen durch "<tt>NetworkManager.service</tt>".


Zeile 338: Zeile 339:




=== 5.2.1. Grafische Netzwerkkonfigurations-Werkzeuge ===
==== Grafische Netzwerkkonfigurations-Werkzeuge ====
Offizielle Dokumentation für NM unter Debian ist in "<tt>/usr/share/doc/network-manager/README.Debian</tt>" verfügbar.
Offizielle Dokumentation für NM unter Debian ist in "<tt>/usr/share/doc/network-manager/README.Debian</tt>" verfügbar.


Zeile 366: Zeile 367:
|}
|}


== 5.3. Moderne Netzwerkkonfiguration ohne grafische Oberfläche ==
=== Moderne Netzwerkkonfiguration ohne grafische Oberfläche ===
Unter [https://de.wikipedia.org/wiki/Systemd systemd] kann das Netzwerk stattdessen in <tt>/etc/systemd/network/</tt> konfiguriert werden. Lesen Sie dazu <tt>systemd-resolved</tt>(8), <tt>resolved.conf</tt>(5) und <tt>systemd-networkd</tt>(8).
Unter [https://de.wikipedia.org/wiki/Systemd systemd] kann das Netzwerk stattdessen in <tt>/etc/systemd/network/</tt> konfiguriert werden. Lesen Sie dazu <tt>systemd-resolved</tt>(8), <tt>resolved.conf</tt>(5) und <tt>systemd-networkd</tt>(8).


Zeile 373: Zeile 374:
Eine DHCP-Client-Konfiguration kann durch Erzeugen von "<tt>/etc/systemd/network/dhcp.network</tt>" eingerichtet werden, z.B. mit:
Eine DHCP-Client-Konfiguration kann durch Erzeugen von "<tt>/etc/systemd/network/dhcp.network</tt>" eingerichtet werden, z.B. mit:


[Match]
[Match]
Name=en*
Name=en*


[Network]
[Network]
DHCP=yes
DHCP=yes


Eine statische Netzwerkkonfiguration richten Sie über "<tt>/etc/systemd/network/static.network</tt>" ein, wie hier:
Eine statische Netzwerkkonfiguration richten Sie über "<tt>/etc/systemd/network/static.network</tt>" ein, wie hier:


[Match]
[Match]
Name=en*
Name=en*


[Network]
[Network]
Address=192.168.0.15/24
Address=192.168.0.15/24
Gateway=192.168.0.1
Gateway=192.168.0.1




== 5.4. Netzwerkkonfiguration auf unterster Ebene ==
=== Netzwerkkonfiguration auf unterster Ebene ===
Für Netzwerkkonfiguration über die Konsole können Sie unter Linux die [http://www.linuxfoundation.org/collaborate/workgroups/networking/iproute2 iproute2]-Programme (<tt>ip</tt>(8), …) verwenden.
Für Netzwerkkonfiguration über die Konsole können Sie unter Linux die [http://www.linuxfoundation.org/collaborate/workgroups/networking/iproute2 iproute2]-Programme (<tt>ip</tt>(8), …) verwenden.




=== 5.4.1. iproute2-Befehle ===
==== iproute2-Befehle ====
Die [http://www.linuxfoundation.org/collaborate/workgroups/networking/iproute2 iproute2]-Befehle bieten vollwertige Funktionalität auf der untersten Ebene der Netzwerkkonfiguration. Hier eine Tabelle zur Gegenüberstellung von veralteten [http://www.linuxfoundation.org/collaborate/workgroups/networking/net-tools net-tools]-Befehlen und neuen [http://www.linuxfoundation.org/collaborate/workgroups/networking/iproute2 iproute2]- und anderen Befehlen.
Die [http://www.linuxfoundation.org/collaborate/workgroups/networking/iproute2 iproute2]-Befehle bieten vollwertige Funktionalität auf der untersten Ebene der Netzwerkkonfiguration. Hier eine Tabelle zur Gegenüberstellung von veralteten [http://www.linuxfoundation.org/collaborate/workgroups/networking/net-tools net-tools]-Befehlen und neuen [http://www.linuxfoundation.org/collaborate/workgroups/networking/iproute2 iproute2]- und anderen Befehlen.


'''Tabelle 5.3. Gegenüberstellung von <tt>net-tools</tt>- und <tt>iproute2</tt>-Befehlen'''
; Gegenüberstellung von <tt>net-tools</tt>- und <tt>iproute2</tt>-Befehlen


{| class="wikitable sortable options"
{| class="wikitable sortable options"
Zeile 437: Zeile 438:




=== 5.4.2. Sichere Basis-Netzwerkoperationen ===
==== Sichere Basis-Netzwerkoperationen ====
Sie können die folgenden Netzwerkbefehle der untersten Ebene problemlos verwenden, da sie die Netzwerkkonfiguration nicht verändern:
Sie können die folgenden Netzwerkbefehle der untersten Ebene problemlos verwenden, da sie die Netzwerkkonfiguration nicht verändern:


'''Tabelle 5.4. Liste von Basis-Netzwerkbefehlen'''
; Tabelle 5.4. Liste von Basis-Netzwerkbefehlen


{| class="wikitable sortable options"
{| class="wikitable sortable options"
Zeile 510: Zeile 511:
|}
|}


== 5.5. Netzwerkoptimierung ==
=== Netzwerkoptimierung ===
Die grundsätzliche Netzwerkoptimierung liegt außerhalb des Rahmens dieser Dokumentation. Ich erwähne hier nur Dinge, die für Anwender-typische Verbindungen passend sind.
Die grundsätzliche Netzwerkoptimierung liegt außerhalb des Rahmens dieser Dokumentation. Ich erwähne hier nur Dinge, die für Anwender-typische Verbindungen passend sind.


'''Tabelle 5.5. Liste von Werkzeugen zur Netzwerkoptimierung'''
; Liste von Werkzeugen zur Netzwerkoptimierung


{| class="wikitable sortable options"
{| class="wikitable sortable options"
Zeile 570: Zeile 571:




=== 5.5.1. Die optimale MTU finden ===
==== Die optimale MTU finden ====
NM setzt den optimalen Wert für die [https://de.wikipedia.org/wiki/Maximum_Transmission_Unit Maximum Transmission Unit (MTU)] normalerweise automatisch.
NM setzt den optimalen Wert für die [https://de.wikipedia.org/wiki/Maximum_Transmission_Unit Maximum Transmission Unit (MTU)] normalerweise automatisch.


In speziellen Fällen möchten Sie die MTU jedoch vielleicht händisch setzen, nachdem Sie mit <tt>ping</tt>(8) und seiner Option "<tt>-M do</tt>" experimentiert haben; Sie haben damit die Möglichkeit, ein ICMP-Paket mit verschiedenen Paketgrößen zu verschicken. MTU ist die größte Paketgröße, bei der das Paket noch erfolgreich ohne Fragmentierung verschickt werden kann plus 28 Byte für die IPv4- bzw. 48 Byte für die IPv6-Adresse. In folgendem Beispiel wurde für eine IPv4-Verbindung eine MTU von 1460 ermittelt und für IPv6 eine MTU von 1500:
In speziellen Fällen möchten Sie die MTU jedoch vielleicht händisch setzen, nachdem Sie mit <tt>ping</tt>(8) und seiner Option "<tt>-M do</tt>" experimentiert haben; Sie haben damit die Möglichkeit, ein ICMP-Paket mit verschiedenen Paketgrößen zu verschicken. MTU ist die größte Paketgröße, bei der das Paket noch erfolgreich ohne Fragmentierung verschickt werden kann plus 28 Byte für die IPv4- bzw. 48 Byte für die IPv6-Adresse. In folgendem Beispiel wurde für eine IPv4-Verbindung eine MTU von 1460 ermittelt und für IPv6 eine MTU von 1500:


$ ping -4 -c 1 -s $((1500-28)) -M do www.debian.org
$ ping -4 -c 1 -s $((1500-28)) -M do www.debian.org
PING (149.20.4.15) 1472(1500) bytes of data.
PING (149.20.4.15) 1472(1500) bytes of data.
ping: local error: message too long, mtu=1460
ping: local error: message too long, mtu=1460
--- ping statistics ---
1 packets transmitted, 0 received, +1 errors, 100% packet loss, time 0ms


--- ping statistics ---
$ ping -4 -c 1 -s $((1460-28)) -M do www.debian.org
1 packets transmitted, 0 received, +1 errors, 100% packet loss, time 0ms
PING (130.89.148.77) 1432(1460) bytes of data.
 
1440 bytes from klecker-misc.debian.org (130.89.148.77): icmp_seq=1 ttl=50 time=325 ms
$ ping -4 -c 1 -s $((1460-28)) -M do www.debian.org
PING (130.89.148.77) 1432(1460) bytes of data.
--- ping statistics ---
1440 bytes from klecker-misc.debian.org (130.89.148.77): icmp_seq=1 ttl=50 time=325 ms
1 packets transmitted, 1 received, 0% packet loss, time 0ms
 
rtt min/avg/max/mdev = 325.318/325.318/325.318/0.000 ms
--- ping statistics ---
$ ping -6 -c 1 -s $((1500-48)) -M do www.debian.org
1 packets transmitted, 1 received, 0% packet loss, time 0ms
PING www.debian.org(mirror-csail.debian.org (2603:400a:ffff:bb8::801f:3e)) 1452 data bytes
rtt min/avg/max/mdev = 325.318/325.318/325.318/0.000 ms
1460 bytes from mirror-csail.debian.org (2603:400a:ffff:bb8::801f:3e): icmp_seq=1 ttl=47 time=191 ms
$ ping -6 -c 1 -s $((1500-48)) -M do www.debian.org
PING www.debian.org(mirror-csail.debian.org (2603:400a:ffff:bb8::801f:3e)) 1452 data bytes
--- www.debian.org ping statistics ---
1460 bytes from mirror-csail.debian.org (2603:400a:ffff:bb8::801f:3e): icmp_seq=1 ttl=47 time=191 ms
1 packets transmitted, 1 received, 0% packet loss, time 0ms
 
rtt min/avg/max/mdev = 191.332/191.332/191.332/0.000 ms
--- www.debian.org ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 191.332/191.332/191.332/0.000 ms


Dies ist das [https://de.wikipedia.org/wiki/Path_MTU_Discovery Path MTU (PMTU) Discovery]-Verfahren ([http://tools.ietf.org/html/rfc1191 RFC1191]) und der Befehl <tt>tracepath</tt>(8) kann dies automatisieren.
Dies ist das [https://de.wikipedia.org/wiki/Path_MTU_Discovery Path MTU (PMTU) Discovery]-Verfahren ([http://tools.ietf.org/html/rfc1191 RFC1191]) und der Befehl <tt>tracepath</tt>(8) kann dies automatisieren.


'''Tabelle 5.6. Wesentliche Grundregeln für den optimalen MTU-Wert'''
; Wesentliche Grundregeln für den optimalen MTU-Wert


{| class="wikitable sortable options"
{| class="wikitable sortable options"
Zeile 617: Zeile 618:
|}
|}


Zusätzlich zu diesen Grundregeln sollten Sie folgendes wissen:* Jegliche Nutzung von Tunneling-Methoden ([https://de.wikipedia.org/wiki/Virtual_Private_Network VPN] usw.) kann aufgrund des Overheads den optimalen MTU-Wert reduzieren.
Zusätzlich zu diesen Grundregeln sollten Sie folgendes wissen:
* Jegliche Nutzung von Tunneling-Methoden ([https://de.wikipedia.org/wiki/Virtual_Private_Network VPN] usw.) kann aufgrund des Overheads den optimalen MTU-Wert reduzieren.
* Der MTU-Wert sollte den über die experimentelle Methode ermittelten PMTU-Wert nicht überschreiten.
* Der MTU-Wert sollte den über die experimentelle Methode ermittelten PMTU-Wert nicht überschreiten.
* Ein größerer MTU-Wert ist grundsätzlich besser, wenn andere Einschränkungen greifen.
* Ein größerer MTU-Wert ist grundsätzlich besser, wenn andere Einschränkungen greifen.


Die [https://de.wikipedia.org/wiki/Maximum_Segment_Size Maximum Segment Size] (MSS) wird als alternative Messmethode für die Paketgröße verwendet. Der Zusammenhang zwischen MSS und MTU ist wie folgt:* MSS = "MTU - 40" bei IPv4
Die [https://de.wikipedia.org/wiki/Maximum_Segment_Size Maximum Segment Size] (MSS) wird als alternative Messmethode für die Paketgröße verwendet. Der Zusammenhang zwischen MSS und MTU ist wie folgt:
* MSS = "MTU - 40" bei IPv4
* MSS = "MTU - 60" bei IPv6
* MSS = "MTU - 60" bei IPv6


Zeile 634: Zeile 637:
|}
|}


=== 5.5.2. WAN-TCP-Optimierung ===
==== WAN-TCP-Optimierung ====
Der TCP-Durchsatz kann über die Anpassung von Parametern zur TCP-Puffergröße maximiert werden, wie es die Anleitungen "[http://dsd.lbl.gov/TCP-tuning/ TCP Tuning Guide]" und "[https://en.wikipedia.org/wiki/TCP_tuning TCP Tuning]" für modernes WAN mit hoher Bandbreite und hoher Latenz beschreiben. Das soll hierzu genügen; die aktuellen Debian-Standardeinstellungen funktionieren für mein LAN mit seiner Verbindung zum sehr schnellen 1G bps FFTP-Dienst sehr gut.
Der TCP-Durchsatz kann über die Anpassung von Parametern zur TCP-Puffergröße maximiert werden, wie es die Anleitungen "[http://dsd.lbl.gov/TCP-tuning/ TCP Tuning Guide]" und "[https://en.wikipedia.org/wiki/TCP_tuning TCP Tuning]" für modernes WAN mit hoher Bandbreite und hoher Latenz beschreiben. Das soll hierzu genügen; die aktuellen Debian-Standardeinstellungen funktionieren für mein LAN mit seiner Verbindung zum sehr schnellen 1G bps FFTP-Dienst sehr gut.




== 5.6. Die Netfilter-Infrastruktur ==
=== Die Netfilter-Infrastruktur ===
[https://de.wikipedia.org/wiki/Netfilter Netfilter] stellt eine Infrastruktur für [https://de.wikipedia.org/wiki/Stateful_Packet_Inspection Stateful Packet Inspection (SPI, zustandsorientierte Paketüberprüfung)] und [https://de.wikipedia.org/wiki/Network_Address_Translation Network Address Translation (NAT)] über Module des [https://de.wikipedia.org/wiki/Linux_(Kernel) Linux-Kernels] (lesen Sie hierzu [https://www.debian.org/doc/manuals/debian-reference/ch03.de.html#_the_kernel_module_initialization Abschnitt 3.8.1, „Die Kernel-Modul-Initialisierung“]) zur Verfügung.
[https://de.wikipedia.org/wiki/Netfilter Netfilter] stellt eine Infrastruktur für [https://de.wikipedia.org/wiki/Stateful_Packet_Inspection Stateful Packet Inspection (SPI, zustandsorientierte Paketüberprüfung)] und [https://de.wikipedia.org/wiki/Network_Address_Translation Network Address Translation (NAT)] über Module des [https://de.wikipedia.org/wiki/Linux_(Kernel) Linux-Kernels] (lesen Sie hierzu [https://www.debian.org/doc/manuals/debian-reference/ch03.de.html#_the_kernel_module_initialization Abschnitt 3.8.1, „Die Kernel-Modul-Initialisierung“]) zur Verfügung.


'''Tabelle 5.7. Liste von Firewall-Werkzeugen'''
; Liste von Firewall-Werkzeugen


{| class="wikitable sortable options"
{| class="wikitable sortable options"
Zeile 717: Zeile 720:




= All About Debian /etc/network/interfaces File =
== All About Debian /etc/network/interfaces File ==
by [https://linuxhint.com/author/david-adams/ David Adams]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.
by [https://linuxhint.com/author/david-adams/ David Adams]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.


Zeile 726: Zeile 729:
Lines beginning with “iface” have the following syntax:
Lines beginning with “iface” have the following syntax:


iface&nbsp; <interface>&nbsp; <address_family>&nbsp; <method>
iface&nbsp; <interface>&nbsp; <address_family>&nbsp; <method>


For example:
For example:


iface enp2s0 inet dhcp
iface enp2s0 inet dhcp


The following example shows how to setup a network card using 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: ===
==== Setting up an interface with DHCP by editing the /etc/network/interfaces: ====
To add a new interface using DHCP, add the following lines:
To add a new interface using DHCP, add the following lines:


Zeile 742: Zeile 745:
[[Image:Bild13.png|top]]Where '''allow-hotplug''' will start the interface upon event detection.
[[Image:Bild13.png|top]]Where '''allow-hotplug''' will start the interface upon event detection.


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


Where '''<interface>''' you should set your device name, '''eth0''', '''enp2s0''', '''wlp3s0''', etc.
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: ===
==== 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
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


Zeile 757: Zeile 760:




=== Setting up a network card with 2 interfaces: ===
==== Setting up a network card with 2 interfaces: ====
The following example below shows a static configuration for a network card with two interfaces:
The following example below shows a static configuration for a network card with two interfaces:


Zeile 765: Zeile 768:




=== Configure network bonding by editing the /etc/network/interfaces: ===
==== 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:
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:


Zeile 774: Zeile 777:
iface bond0 inet staticaddress 192.168.0.54netmask 255.255.255.0network 192.168.0.0gateway 192.168.0.1
iface bond0 inet staticaddress 192.168.0.54netmask 255.255.255.0network 192.168.0.0gateway 192.168.0.1


[[Image:Bild18.png|top]]You can run the following command to make sure bonding is working properly:<nowiki># cat /proc/net/bonding/bond0</nowiki>
[[Image:Bild18.png|top]]You can run the following command to make sure bonding is working properly:# cat /proc/net/bonding/bond0


[[Image:Bild19.png|top]]
[[Image:Bild19.png|top]]
Zeile 781: Zeile 784:




=== Enable logging for the file /etc/network/interfaces: ===
==== Enable logging for the file /etc/network/interfaces: ====
There are 3 options related to the logging:
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.
; VERBOSE: '''instructs log files to have detailed information.'''DEBUG: '''enable debugging when logging.'''SYSLOG: save logs within /var/log/syslog.


[[Image:Bild20.png|top]]'''Pre-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.
[[Image:Bild20.png|top]]'''Pre-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.
; 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-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.
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.
Zeile 802: Zeile 805:
Quelle: https://linuxhint.com/debian_etc_network_interfaces/
Quelle: https://linuxhint.com/debian_etc_network_interfaces/


= 3 ways to configure the network =
== 3 ways to configure the network ==
* The interfaces configuration file at /etc/network/interfaces (this page): for basic or simple configurations (e.g. workstation)
* The interfaces configuration file at /etc/network/interfaces (this page): for basic or simple configurations (e.g. workstation)
* [https://wiki.debian.org/NetworkManager NetworkManager]: This is the default for Laptop configuration
* [https://wiki.debian.org/NetworkManager NetworkManager]: This is the default for Laptop configuration
Zeile 808: Zeile 811:




= Setting up an Ethernet Interface =
== Setting up an Ethernet Interface ==
The majority of network setup can be done via the <tt>'''interfaces'''</tt> configuration file at <tt>'''/etc/network/interfaces'''</tt>. Here, you can give your network card an IP address (or use dhcp), set up routing information, configure IP masquerading, set default routes and much more.
The majority of network setup can be done via the <tt>'''interfaces'''</tt> configuration file at <tt>'''/etc/network/interfaces'''</tt>. Here, you can give your network card an IP address (or use dhcp), set up routing information, configure IP masquerading, set default routes and much more.


Zeile 816: Zeile 819:




== Starting and Stopping Interfaces ==
=== Starting and Stopping Interfaces ===
Interfaces configured with <tt>/etc/network/interfaces</tt> can be brought up and down with the [https://manpages.debian.org/man/ifup ifup] and [https://manpages.debian.org/man/ifdown ifdown] commands.
Interfaces configured with <tt>/etc/network/interfaces</tt> can be brought up and down with the [https://manpages.debian.org/man/ifup ifup] and [https://manpages.debian.org/man/ifdown ifdown] commands.


Some outdated guides instruct to restart the networking service to apply changes to <tt>/etc/network/interfaces</tt>, however this was deprecated because it is possible that not all interfaces will be restarted. Instead use <tt>ifup</tt> and <tt>ifdown</tt> to apply changes to each interface, for example with an interface named enp7s0:
Some outdated guides instruct to restart the networking service to apply changes to <tt>/etc/network/interfaces</tt>, however this was deprecated because it is possible that not all interfaces will be restarted. Instead use <tt>ifup</tt> and <tt>ifdown</tt> to apply changes to each interface, for example with an interface named enp7s0:


<nowiki># ifdown enp7s0</nowiki>
# ifdown enp7s0
<nowiki># ifup enp7s0</nowiki>
# ifup enp7s0




== Reinitialize new network setup ==
=== Reinitialize new network setup ===
If you make more fundamental network changes e.g. adding new virtual interfaces (e.g. bridge) in <tt>/etc/network/interfaces</tt> you can reinitialize the network-configuration be restarting the <tt>networking</tt> daemon:
If you make more fundamental network changes e.g. adding new virtual interfaces (e.g. bridge) in <tt>/etc/network/interfaces</tt> you can reinitialize the network-configuration be restarting the <tt>networking</tt> daemon:


<nowiki># systemctl status networking</nowiki>
# systemctl status networking
<nowiki># systemctl restart networking</nowiki>
# systemctl restart networking




== Network Interface Names ==
=== Network Interface Names ===
See [https://wiki.debian.org/NetworkInterfaceNames NetworkInterfaceNames]. Since Stretch, new systems by default no longer use old-style interface names such as eth0, eth1, wlan0, wlan1. The new system uses names based on hardware location, like eno0, enp0s31f6, wlp1s7 (or in the case of USB dongles, MAC address: enx2c56ac39ec0d).
See [https://wiki.debian.org/NetworkInterfaceNames NetworkInterfaceNames]. Since Stretch, new systems by default no longer use old-style interface names such as eth0, eth1, wlan0, wlan1. The new system uses names based on hardware location, like eno0, enp0s31f6, wlp1s7 (or in the case of USB dongles, MAC address: enx2c56ac39ec0d).


Zeile 840: Zeile 843:




=== Upgrading and Network Interface Names ===
==== Upgrading and Network Interface Names ====
Stretch and Buster still retain support for the old naming system as long as the file <tt>/etc/udev/rules.d/70-local-persistent-net.rules</tt> is still in place, but users are advised to switch ahead of the upgrade to Bullseye.
Stretch and Buster still retain support for the old naming system as long as the file <tt>/etc/udev/rules.d/70-local-persistent-net.rules</tt> is still in place, but users are advised to switch ahead of the upgrade to Bullseye.




== Using DHCP to automatically configure the interface ==
=== Using DHCP to automatically configure the interface ===
If you're just using DHCP then all you need is something like:
If you're just using DHCP then all you need is something like:


Zeile 862: Zeile 865:




== Configuring the interface manually ==
=== Configuring the interface manually ===
If you're configuring it manually then something like this will set the default gateway (network, broadcast and gateway are optional):
If you're configuring it manually then something like this will set the default gateway (network, broadcast and gateway are optional):


Zeile 882: Zeile 885:
Mixing manual and automatic configuration is also possible, e.g. to use IPv6 SLAAC for internet connectivity and static addresses within the network:
Mixing manual and automatic configuration is also possible, e.g. to use IPv6 SLAAC for internet connectivity and static addresses within the network:


<nowiki># manual unique local address</nowiki>
# manual unique local address
iface eth0 inet6 static
iface eth0 inet6 static
address fdc3:cafe::3/64
  address fdc3:cafe::3/64
<nowiki># use SLAAC to get global IPv6 address from the router</nowiki>
  # use SLAAC to get global IPv6 address from the router
<nowiki># we may not enable ipv6 forwarding, otherwise SLAAC gets disabled</nowiki>
  # we may not enable ipv6 forwarding, otherwise SLAAC gets disabled
autoconf 1
  autoconf 1
accept_ra 2
  accept_ra 2




== Setting the speed and duplex ==
=== Setting the speed and duplex ===
Autonegotiation repeatedly failing is often a symptom of faulty cabling, so investigate physical matters before assuming that the interfaces' autonegotiation algorithms are incompatible. If you turn off autonegotiation and set speed and duplex manually then the partner interface at the other end of the cable will assume that the absence of autonegotiation indicates a speed of 10Mbps and a duplex of half. For error-free operation if you set speed and duplex manually you must ensure that exactly the same speed and duplex are configured on the partner interface.
Autonegotiation repeatedly failing is often a symptom of faulty cabling, so investigate physical matters before assuming that the interfaces' autonegotiation algorithms are incompatible. If you turn off autonegotiation and set speed and duplex manually then the partner interface at the other end of the cable will assume that the absence of autonegotiation indicates a speed of 10Mbps and a duplex of half. For error-free operation if you set speed and duplex manually you must ensure that exactly the same speed and duplex are configured on the partner interface.


Zeile 910: Zeile 913:




== Bringing up an interface without an IP address ==
=== Bringing up an interface without an IP address ===
To create a network interface without an IP address at all use the manual method and use pre-up and post-down commands to bring the interface up and down.
To create a network interface without an IP address at all use the manual method and use pre-up and post-down commands to bring the interface up and down.


Zeile 926: Zeile 929:




= Defining the (DNS) Nameservers =
== Defining the (DNS) Nameservers ==
Before a computer can connect to an external network resource (say, for example, a web server), it must have a means of converting any alpha-numeric names (e.g. wiki.debian.org) into numeric network addresses (e.g. 140.211.166.4). (The Internet uses these structured numeric IP addresses as network addresses.)
Before a computer can connect to an external network resource (say, for example, a web server), it must have a means of converting any alpha-numeric names (e.g. wiki.debian.org) into numeric network addresses (e.g. 140.211.166.4). (The Internet uses these structured numeric IP addresses as network addresses.)


Zeile 938: Zeile 941:




== The resolv.conf configuration file ==
=== The resolv.conf configuration file ===
The configuration file <tt>'''resolv.conf'''</tt> at <tt>/etc/resolv.conf</tt> contains information that allows a computer connected to a network to resolve names into addresses. (Note: Do not confuse this ''configuration file'' with the ''program'' <tt>'''resolvconf'''</tt>, which unfortunately has a nearly identical name.)
The configuration file <tt>'''resolv.conf'''</tt> at <tt>/etc/resolv.conf</tt> contains information that allows a computer connected to a network to resolve names into addresses. (Note: Do not confuse this ''configuration file'' with the ''program'' <tt>'''resolvconf'''</tt>, which unfortunately has a nearly identical name.)


The <tt>'''resolv.conf'''</tt> file typically contains the IP addresses of nameservers (DNS name resolvers) that will attempt to translate names into addresses for any node available on the network. There will be a line or lines that look like this:
The <tt>'''resolv.conf'''</tt> file typically contains the IP addresses of nameservers (DNS name resolvers) that will attempt to translate names into addresses for any node available on the network. There will be a line or lines that look like this:


nameserver 12.34.56.78
nameserver 12.34.56.78
nameserver 12.34.56.79
nameserver 12.34.56.79


In this example, the system is using nameservers at the IP addresses <tt>12.34.56.78</tt> and <tt>12.34.56.79</tt>. Simply edit the file and enter the IP addresses of the nameservers you need to use after each <tt>nameserver</tt>. Add more <tt>nameserver</tt> lines if you have more nameservers. '''Don't use this method if you have the '''<tt>resolvconf</tt>''' program installed.'''
In this example, the system is using nameservers at the IP addresses <tt>12.34.56.78</tt> and <tt>12.34.56.79</tt>. Simply edit the file and enter the IP addresses of the nameservers you need to use after each <tt>nameserver</tt>. Add more <tt>nameserver</tt> lines if you have more nameservers. '''Don't use this method if you have the '''<tt>resolvconf</tt>''' program installed.'''
Zeile 951: Zeile 954:




== The resolvconf program ==
=== The resolvconf program ===
The <tt>'''resolvconf'''</tt> program keeps track of system information about the currently available nameservers. It should not be confused with the ''configuration file'' <tt>'''resolv.conf'''</tt>, which unfortunately has a nearly identical name. The <tt>'''resolvconf'''</tt> program is optional on a Debian system.
The <tt>'''resolvconf'''</tt> program keeps track of system information about the currently available nameservers. It should not be confused with the ''configuration file'' <tt>'''resolv.conf'''</tt>, which unfortunately has a nearly identical name. The <tt>'''resolvconf'''</tt> program is optional on a Debian system.


Zeile 962: Zeile 965:
If the <tt>'''resolvconf'''</tt> program is installed, you should not edit the <tt>'''resolv.conf'''</tt> configuration file manually as it will be dynamically changed by programs in the system. If you need to manually define the nameservers (as with a static interface), add a line something like the following to the <tt>'''interfaces'''</tt> configuration file at <tt>/etc/network/interfaces</tt>:
If the <tt>'''resolvconf'''</tt> program is installed, you should not edit the <tt>'''resolv.conf'''</tt> configuration file manually as it will be dynamically changed by programs in the system. If you need to manually define the nameservers (as with a static interface), add a line something like the following to the <tt>'''interfaces'''</tt> configuration file at <tt>/etc/network/interfaces</tt>:


dns-nameservers 12.34.56.78 12.34.56.79
dns-nameservers 12.34.56.78 12.34.56.79


Place the line indented within an <tt>iface</tt> stanza, e.g., right after the <tt>gateway</tt> line. Enter the IP addresses of the nameservers you need to use after <tt>dns-nameservers</tt>. Put all of them on one line separated by spaces. Don't forget the "<tt>s</tt>" on the end of <tt>dns-nameservers</tt>.
Place the line indented within an <tt>iface</tt> stanza, e.g., right after the <tt>gateway</tt> line. Enter the IP addresses of the nameservers you need to use after <tt>dns-nameservers</tt>. Put all of them on one line separated by spaces. Don't forget the "<tt>s</tt>" on the end of <tt>dns-nameservers</tt>.
Zeile 969: Zeile 972:




== DNS configuration for NetworkManager ==
=== DNS configuration for NetworkManager ===
[https://wiki.debian.org/NetworkManager NetworkManager] will override dhcp settings, overwriting resolv.conf even if you've configured DNS in /etc/dhcp/dhclient.conf, e.g. causing DNS to first search the local domain, which may have to time out before DNS resolution continues causing lengthy DNS resolution times. You can get an idea of what [https://wiki.debian.org/NetworkManager NetworkManager] thinks the settings should be by executing nm-tool at the command line.
[https://wiki.debian.org/NetworkManager NetworkManager] will override dhcp settings, overwriting resolv.conf even if you've configured DNS in /etc/dhcp/dhclient.conf, e.g. causing DNS to first search the local domain, which may have to time out before DNS resolution continues causing lengthy DNS resolution times. You can get an idea of what [https://wiki.debian.org/NetworkManager NetworkManager] thinks the settings should be by executing nm-tool at the command line.


Zeile 980: Zeile 983:
[https://wiki.debian.org/NetworkManager NetworkManager] saves these settings in <tt>/etc/NetworkManager/system-connections/name-of-connection</tt>. Example <tt>/etc/NetworkManager/system-connections/Wired&nbsp;connection&nbsp;1</tt> :
[https://wiki.debian.org/NetworkManager NetworkManager] saves these settings in <tt>/etc/NetworkManager/system-connections/name-of-connection</tt>. Example <tt>/etc/NetworkManager/system-connections/Wired&nbsp;connection&nbsp;1</tt> :


[802-3-ethernet]
[802-3-ethernet]
duplex=full
duplex=full
mac-address=XX:XX:XX:XX:XX:XX
mac-address=XX:XX:XX:XX:XX:XX
 
[connection]
[connection]
id=Wired connection 1
id=Wired connection 1
uuid=xxx-xxxxxx-xxxxxx-xxxxxx-xxx
uuid=xxx-xxxxxx-xxxxxx-xxxxxx-xxx
type=802-3-ethernet
type=802-3-ethernet
timestamp=1385213042
timestamp=1385213042
 
[ipv6]
[ipv6]
method=auto
method=auto
 
[ipv4]
[ipv4]
method=auto
method=auto
dns=208.67.222.222;
dns=208.67.222.222;
ignore-auto-dns=true
ignore-auto-dns=true


Running nm-tool again should show that [https://wiki.debian.org/NetworkManager NetworkManager] now has the right idea of how your DNS should be resolved.
Running nm-tool again should show that [https://wiki.debian.org/NetworkManager NetworkManager] now has the right idea of how your DNS should be resolved.




== DHCP Client Configuration ==
=== DHCP Client Configuration ===


=== Setting additional DNS Servers ===
==== Setting additional DNS Servers ====
Example: dhclient3 uses <tt>/etc/dhcp/dhclient.conf</tt>. The setting you want is
Example: dhclient3 uses <tt>/etc/dhcp/dhclient.conf</tt>. The setting you want is


supersede domain-name-servers 12.34.56.78, 12.34.56.79;
supersede domain-name-servers 12.34.56.78, 12.34.56.79;


or perhaps
or perhaps


prepend domain-name-servers 12.34.56.78, 12.34.56.79;
prepend domain-name-servers 12.34.56.78, 12.34.56.79;




=== Setting additional search domains ===
==== Setting additional search domains ====
adding search domains for VPNs or local virtual networks:
adding search domains for VPNs or local virtual networks:


append domain-name " virt vpn";
append domain-name " virt vpn";


Note the leading space since the string is literally appended to the search domain provided by other configurations.
Note the leading space since the string is literally appended to the search domain provided by other configurations.
Zeile 1.023: Zeile 1.026:




= Bridging =
== Bridging ==
Bridging puts multiple interfaces into the same network segment. This is very popular when connecting a server to multiple switches for high availability or with virtualization. In the latter case it is usually used to create a bridge in the host (eg. dom0) and put the virtual interfaces of the guests (domU) into the bridge. * The [https://packages.debian.org/bridge-utils bridge-utils] package is required to create bridged interfaces.
Bridging puts multiple interfaces into the same network segment. This is very popular when connecting a server to multiple switches for high availability or with virtualization. In the latter case it is usually used to create a bridge in the host (eg. dom0) and put the virtual interfaces of the guests (domU) into the bridge. * The [https://packages.debian.org/bridge-utils bridge-utils] package is required to create bridged interfaces.


Example: Connect a server to 2 switches (via eth0 and eth1) by defining bridge 0 and give the server an IP address in this subnet:
Example: Connect a server to 2 switches (via eth0 and eth1) by defining bridge 0 and give the server an IP address in this subnet:


auto br0
auto br0
iface br0 inet static
iface br0 inet static
address 10.10.0.15/24
  address 10.10.0.15/24
gateway 10.10.0.1
  gateway 10.10.0.1
bridge_ports eth0 eth1
  bridge_ports eth0 eth1
up /usr/sbin/brctl stp br0 on
  up /usr/sbin/brctl stp br0 on


If a server is connected to multiple switches then you usually need to run the spanning tree protocol to avoid loops. Therefore STP must be turned on via an "up" command as shown above.
If a server is connected to multiple switches then you usually need to run the spanning tree protocol to avoid loops. Therefore STP must be turned on via an "up" command as shown above.
Zeile 1.039: Zeile 1.042:
Example: Bridge setup without IP address configuration (use "manual" instead of "static") to "forward" an interface to a guest VM. (The static bridge config contains only 1 physical interface. The virtual interface will be added to the bridge when the VM is started.)
Example: Bridge setup without IP address configuration (use "manual" instead of "static") to "forward" an interface to a guest VM. (The static bridge config contains only 1 physical interface. The virtual interface will be added to the bridge when the VM is started.)


auto br1
auto br1
iface br1 inet manual
iface br1 inet manual
bridge_ports eth4
  bridge_ports eth4
up /usr/sbin/brctl setageing br1 0
  up /usr/sbin/brctl setageing br1 0
up /usr/sbin/brctl stp br1 off
  up /usr/sbin/brctl stp br1 off


Note: The Linux bridge supports only STP, no RSTP (Rapid Spanning Tree). Therefore it supports only the old STP Costs, not the new RSTP Costs (see [https://en.wikipedia.org/wiki/Spanning_Tree_Protocol#Data_rate_and_STP_path_cost Spanning_Tree_Protocol]). This is usually fine with Cisco Switches, but eg. Juniper switches use the RSTP costs and therefore this may lead to different spanning tree calculations and loop problems. This can be fixed by settings the costs manually, either on the switch or on the server. Setting the cost on the switch is preferred as Linux switches back to the default costs whenever an interface does down/up.
Note: The Linux bridge supports only STP, no RSTP (Rapid Spanning Tree). Therefore it supports only the old STP Costs, not the new RSTP Costs (see [https://en.wikipedia.org/wiki/Spanning_Tree_Protocol#Data_rate_and_STP_path_cost Spanning_Tree_Protocol]). This is usually fine with Cisco Switches, but eg. Juniper switches use the RSTP costs and therefore this may lead to different spanning tree calculations and loop problems. This can be fixed by settings the costs manually, either on the switch or on the server. Setting the cost on the switch is preferred as Linux switches back to the default costs whenever an interface does down/up.




== Bridging without Switching ==
=== Bridging without Switching ===
By default the Linux bridge acts like a switch. This means, it remembers the MAC addresses behind a switch port and if the destination MAC address is known, data packets or only forward to the respective port - otherwise packets will be broadcasted.
By default the Linux bridge acts like a switch. This means, it remembers the MAC addresses behind a switch port and if the destination MAC address is known, data packets or only forward to the respective port - otherwise packets will be broadcasted.


Zeile 1.057: Zeile 1.060:




= Howto use vlan (dot1q, 802.1q, trunk) (Etch, Lenny) =
== Howto use vlan (dot1q, 802.1q, trunk) (Etch, Lenny) ==
 
== Manual config ==
modprobe 8021q
 
apt install vlan


vconfig add eth0 222 <nowiki># 222 is vlan number</nowiki>
=== Manual config ===
ifconfig eth0.222 up
modprobe 8021q
ifconfig eth0.222 mtu 1496 <nowiki>#optional if your network card doesn't support MTU 1504B</nowiki>
ifconfig eth0.222 10.10.10.1 netmask 255.255.255.0
apt install vlan
vconfig add eth0 222 # 222 is vlan number
ifconfig eth0.222 up
ifconfig eth0.222 mtu 1496 #optional if your network card doesn't support MTU 1504B
ifconfig eth0.222 10.10.10.1 netmask 255.255.255.0




== Network init script config ==
=== Network init script config ===
Into /etc/modules add line:
Into /etc/modules add line:


8021q
8021q


In /etc/network/interfaces to section iface add parameter:
In /etc/network/interfaces to section iface add parameter:
Zeile 1.085: Zeile 1.088:
Eg:
Eg:


auto eth0.222
auto eth0.222
iface eth0.222 inet static
iface eth0.222 inet static
address 10.10.10.1/24
  address 10.10.10.1/24
vlan-raw-device eth0
  vlan-raw-device eth0




== Bridges and VLANs ==
=== Bridges and VLANs ===
If you create VLAN interfaces only to put them into a bridge, there is no need to define the VLAN interfaces manually. Just config the bridge, and the VLAN interface will be created automatically when creating the bridge, e.g:
If you create VLAN interfaces only to put them into a bridge, there is no need to define the VLAN interfaces manually. Just config the bridge, and the VLAN interface will be created automatically when creating the bridge, e.g:


auto br1
auto br1
iface br1 inet manual
iface br1 inet manual
bridge_ports eth0.99 eth1.99
  bridge_ports eth0.99 eth1.99
up /usr/sbin/brctl stp br1 on
  up /usr/sbin/brctl stp br1 on




== Caveats when using bridging and vlan ==
=== Caveats when using bridging and vlan ===
<nowiki>#/etc/network/interfaces</nowiki>
#/etc/network/interfaces
auto eth0 bri0
auto eth0 bri0
iface eth0 inet static
iface eth0 inet static
address 192.168.1.1/24
  address 192.168.1.1/24
iface eth0.110 inet manual
iface eth0.110 inet manual
vlan-raw-device eth0
  vlan-raw-device eth0
iface bri0 inet static
iface bri0 inet static
address 192.168.110.1/24
  address 192.168.110.1/24
bridge_ports eth0.110
  bridge_ports eth0.110
bridge_stp on
  bridge_stp on
bridge_maxwait 10
  bridge_maxwait 10


If you are using a brigded VLAN setup, which is probably useful for networking in virtualization environments, take care to only attach either a bridge device or VLAN devices to an underlying physical device - like shown above. Attaching the physical interface (eth0) to a bridge (eg. bri1) while using the same physical interface on apparently different VLANs will result in all packets to remain tagged. (Kernel newer than 2.6.37 and older than 3.2).
If you are using a brigded VLAN setup, which is probably useful for networking in virtualization environments, take care to only attach either a bridge device or VLAN devices to an underlying physical device - like shown above. Attaching the physical interface (eth0) to a bridge (eg. bri1) while using the same physical interface on apparently different VLANs will result in all packets to remain tagged. (Kernel newer than 2.6.37 and older than 3.2).




= Howto create fault tolerant bonding with vlan (Etch - Stretch) =
== Howto create fault tolerant bonding with vlan (Etch - Stretch) ==
[[Image:Bild21.png|top|alt="debian_bonding.png"]]
[[Image:Bild21.png|top|alt="debian_bonding.png"]]


Zeile 1.123: Zeile 1.126:
How to configure one of the above server active backup bonding 3 vlan {vlan10,vlan20,vlan30} Debian networking without SPOF without native vlan.
How to configure one of the above server active backup bonding 3 vlan {vlan10,vlan20,vlan30} Debian networking without SPOF without native vlan.


aptitude install vlan ifenslave-2.6
aptitude install vlan ifenslave-2.6




== Network config ==
=== Network config ===
Cisco switch interface example config
Cisco switch interface example config


interface GigabitEthernet1/2
interface GigabitEthernet1/2
description eth1
  description eth1
switchport
  switchport
switchport trunk encapsulation dot1q
  switchport trunk encapsulation dot1q
switchport trunk allowed vlan 10,20,30
  switchport trunk allowed vlan 10,20,30
switchport mode trunk
  switchport mode trunk
no ip address
  no ip address
no cdp enable
  no cdp enable
spanning-tree portfast trunk
  spanning-tree portfast trunk




== bonding with active backup ==
=== bonding with active backup ===
Create a file <tt>/etc/modprobe.d/bonding.conf</tt> containing:
Create a file <tt>/etc/modprobe.d/bonding.conf</tt> containing:


alias bond0 bonding
alias bond0 bonding
options bonding mode=active-backup miimon=100 downdelay=200 updelay=200 primary=eth1
options bonding mode=active-backup miimon=100 downdelay=200 updelay=200 primary=eth1




== /etc/network/interfaces ==
=== /etc/network/interfaces ===
<nowiki># The loopback network interface</nowiki>
# The loopback network interface
auto lo
auto lo
iface lo inet loopback
iface lo inet loopback
<nowiki># The primary network interface</nowiki>
# The primary network interface
auto bond0
auto bond0
iface bond0 inet manual
iface bond0 inet manual
up ifconfig bond0 0.0.0.0 up
  up ifconfig bond0 0.0.0.0 up
slaves eth1 eth0
  slaves eth1 eth0
auto vlan10
auto vlan10
iface vlan10 inet static
iface vlan10 inet static
address 10.10.10.12/24
  address 10.10.10.12/24
vlan-raw-device bond0
  vlan-raw-device bond0
gateway 10.10.0.1
  gateway 10.10.0.1
dns-search hup.hu
  dns-search hup.hu
dns-nameservers 10.10.0.2
  dns-nameservers 10.10.0.2
auto vlan20
auto vlan20
iface vlan20 inet static
iface vlan20 inet static
address 10.20.10.12/24
  address 10.20.10.12/24
vlan-raw-device bond0
  vlan-raw-device bond0
auto vlan30
auto vlan30
iface vlan30 inet static
iface vlan30 inet static
address 10.30.10.12/24
  address 10.30.10.12/24
vlan-raw-device bond0* In Debian Buster, you must use interface names for VLANs in the form of: <tt>bond0.10</tt>, <tt>bond0.20</tt>, and <tt>bond0.30</tt> instead of <tt>vlan10</tt>, <tt>vlan20</tt>, <tt>vlan30</tt>
  vlan-raw-device bond0
* In Debian Buster, you must use interface names for VLANs in the form of: <tt>bond0.10</tt>, <tt>bond0.20</tt>, and <tt>bond0.30</tt> instead of <tt>vlan10</tt>, <tt>vlan20</tt>, <tt>vlan30</tt>
* [https://www.kernel.org/doc/Documentation/networking/bonding.txt https://www.kernel.org/doc/Documentation/networking/bonding.txt] - Linux kernel documentation on bonding
* [https://www.kernel.org/doc/Documentation/networking/bonding.txt https://www.kernel.org/doc/Documentation/networking/bonding.txt] - Linux kernel documentation on bonding
* [https://www.dm.unibo.it/~donatini/admin/rete/bonding.html https://www.dm.unibo.it/~donatini/admin/rete/bonding.html] - Bonding on Linux 2.6
* [https://www.dm.unibo.it/~donatini/admin/rete/bonding.html https://www.dm.unibo.it/~donatini/admin/rete/bonding.html] - Bonding on Linux 2.6




== How to set the MTU (Max transfer unit / packet size) with VLANS over a bonded interface ==
=== How to set the MTU (Max transfer unit / packet size) with VLANS over a bonded interface ===
MTU needs to be configured on the bonding interface and slave interfaces after the reset of the configuration has been applied to the bonding interfaces. This is done using a post-up line in the bonding interface configuration.
MTU needs to be configured on the bonding interface and slave interfaces after the reset of the configuration has been applied to the bonding interfaces. This is done using a post-up line in the bonding interface configuration.


auto bond0
auto bond0
iface bond0 inet manual
iface bond0 inet manual
up ifconfig lacptrunk0 0.0.0.0 up
  up ifconfig lacptrunk0 0.0.0.0 up
slaves eth0 eth1
  slaves eth0 eth1
<nowiki># bond-mode 4 = 802.3ad</nowiki>
# bond-mode 4 = 802.3ad
bond-mode 4
  bond-mode 4
bond-miimon 100
  bond-miimon 100
bond-downdelay 200
  bond-downdelay 200
bond-updelay 200
  bond-updelay 200
bond-lacp-rate 1
  bond-lacp-rate 1
bond-xmit-hash-policy layer2+3
  bond-xmit-hash-policy layer2+3
post-up ifconfig eth0 mtu 9000 && ifconfig eth1 mtu 9000 && ifconfig bond0 mtu 9000
  post-up ifconfig eth0 mtu 9000 && ifconfig eth1 mtu 9000 && ifconfig bond0 mtu 9000
 
<nowiki>#vlan devices will use the MTU set on bond0 device</nowiki>
#vlan devices will use the MTU set on bond0 device
auto vlan101
auto vlan101
iface vlan101 inet static
iface vlan101 inet static
 
  address 10.101.60.123/24
  address 10.101.60.123/24
  gateway 10.155.60.1
  gateway 10.155.60.1
  vlan-raw-device bond0
  vlan-raw-device bond0
 
auto vlan151
auto vlan151
iface vlan151 inet static
iface vlan151 inet static
 
  address 192.168.1.1/24
  address 192.168.1.1/24
  vlan-raw-device bond0
  vlan-raw-device bond0




= Multiple IP addresses on one Interface =
== Multiple IP addresses on one Interface ==
Interface aliasing allows one interface to have multiple IP addresses. This is useful when more than one server is to be visible ''via'' the Internet. Note that virtual hosts can support multiple Apache servers with a single IP address. Apache responds to the domain name supplied by the client in the HTTP header. In many other situations, one external IP is needed for each server using a port.
Interface aliasing allows one interface to have multiple IP addresses. This is useful when more than one server is to be visible ''via'' the Internet. Note that virtual hosts can support multiple Apache servers with a single IP address. Apache responds to the domain name supplied by the client in the HTTP header. In many other situations, one external IP is needed for each server using a port.




== Legacy method ==
=== Legacy method ===
This /etc/network/interfaces text assigns three IP addresses to eth0.
This /etc/network/interfaces text assigns three IP addresses to eth0.


auto eth0
auto eth0
allow-hotplug eth0
allow-hotplug eth0
iface eth0 inet static
iface eth0 inet static
address 192.168.1.42/24
  address 192.168.1.42/24
gateway 192.168.1.1
  gateway 192.168.1.1
 
auto eth0:0
auto eth0:0
allow-hotplug eth0:0
allow-hotplug eth0:0
iface eth0:0 inet static
iface eth0:0 inet static
address 192.168.1.43/24
  address 192.168.1.43/24
 
auto eth0:1
auto eth0:1
allow-hotplug eth0:1
allow-hotplug eth0:1
iface eth0:1 inet static
iface eth0:1 inet static
address 192.168.1.44/24
  address 192.168.1.44/24


An alias interface should not have "gateway" or "dns-nameservers"; dynamic IP assignment is permissible.
An alias interface should not have "gateway" or "dns-nameservers"; dynamic IP assignment is permissible.
Zeile 1.236: Zeile 1.241:




== iproute2 method ==
=== iproute2 method ===
Also, ''ifupdown'' supports specifying multiple interfaces by repeating ''iface'' sections with the same interface name. The key difference from the method described above is that all such sections are treated by ''ifupdown'' as just one interface, so user can't add or remove them individually. However, ''up''/''down'' commands, as well as scripts, are called for every section as it used to be.
Also, ''ifupdown'' supports specifying multiple interfaces by repeating ''iface'' sections with the same interface name. The key difference from the method described above is that all such sections are treated by ''ifupdown'' as just one interface, so user can't add or remove them individually. However, ''up''/''down'' commands, as well as scripts, are called for every section as it used to be.


Zeile 1.243: Zeile 1.248:
This /etc/network/interfaces text assigns three IP addresses to eth0.
This /etc/network/interfaces text assigns three IP addresses to eth0.


auto eth0
auto eth0
allow-hotplug eth0
allow-hotplug eth0
iface eth0 inet static
iface eth0 inet static
address 192.168.1.42/24
  address 192.168.1.42/24
gateway 192.168.1.1
  gateway 192.168.1.1


iface eth0 inet static
iface eth0 inet static
address 192.168.1.43/24
  address 192.168.1.43/24


iface eth0 inet static
iface eth0 inet static
address 192.168.1.44/24
  address 192.168.1.44/24


<nowiki># adding IP addresses from different subnets is also possible</nowiki>
# adding IP addresses from different subnets is also possible
iface eth0 inet static
iface eth0 inet static
address 10.10.10.14/24
  address 10.10.10.14/24


Manual approach:
Manual approach:


auto eth0
auto eth0
allow-hotplug eth0
allow-hotplug eth0
iface eth0 inet static
iface eth0 inet static
address 192.168.1.42/24
  address 192.168.1.42/24
gateway 192.168.1.1
  gateway 192.168.1.1
up ip addr add 192.168.1.43/24 dev $IFACE label $IFACE:0
  up ip addr add 192.168.1.43/24 dev $IFACE label $IFACE:0
down ip addr del 192.168.1.43/24 dev $IFACE label $IFACE:0
  down ip addr del 192.168.1.43/24 dev $IFACE label $IFACE:0
up ip addr add 192.168.1.44/24 dev $IFACE label $IFACE:1
  up ip addr add 192.168.1.44/24 dev $IFACE label $IFACE:1
down ip addr del 192.168.1.44/24 dev $IFACE label $IFACE:1
  down ip addr del 192.168.1.44/24 dev $IFACE label $IFACE:1
up ip addr add 10.10.10.14/24 dev $IFACE label $IFACE:2
  up ip addr add 10.10.10.14/24 dev $IFACE label $IFACE:2
down ip addr del 10.10.10.14/24 dev $IFACE label $IFACE:2
  down ip addr del 10.10.10.14/24 dev $IFACE label $IFACE:2


Quelle: [https://wiki.debian.org/NetworkConfiguration https://wiki.debian.org/NetworkConfiguration]
Quelle: [https://wiki.debian.org/NetworkConfiguration https://wiki.debian.org/NetworkConfiguration]
[[Kategorie:Entwurf]]
[[Kategorie:Entwurf]]
[[Kategorie:Linux:Netzwerk]]
[[Kategorie:Linux:Netzwerk]]

Version vom 23. Januar 2023, 09:19 Uhr

Netzwerkkonfiguration

"[Tipp]" Tipp
Bezüglich einer aktuellen Anleitung für Debian zum Thema Netzwerk lesen Sie Debian Administratorhandbuch — Konfigurieren des Netzwerks.
"[Tipp]" Tipp
Unter systemd kann networkd für die Netzwerkverwaltung genutzt werden; lesen Sie dazu systemd-networkd(8).

Die elementare Netzwerkinfrastruktur

Lassen Sie uns einen Blick auf die elementare Netzwerkinfrastruktur eines modernen Debian-Systems werfen:

Pakete Popcon Größe Art Beschreibung
network-manager V:369, I:440 14500 config::NM NetworkManager (Daemon): das Netzwerk automatisch verwalten
network-manager-gnome V:126, I:371 5350 config::NM NetworkManager (GNOME-Frontend)
ifupdown V:584, I:987 217 config::ifupdown standardisiertes Werkzeug zum Aktivieren und Deaktivieren des Netzwerks (Debian-spezifisch)
isc-dhcp-client V:219, I:982 689 config::low-level DHCP-Client
pppoeconf V:0, I:7 192 config::helper Konfigurations-Hilfswerkzeug für PPPoE-Verbindungen
wpasupplicant V:341, I:503 3817 " clientseitige Unterstützung für WPA und WPA2 (IEEE 802.11i)
wpagui V:0, I:2 800 " Qt-GUI-Programm für wpa_supplicant
wireless-tools V:176, I:239 297 " Werkzeuge zum Bearbeiten der Linux Wireless Extensions
iw V:223, I:477 294 " Werkzeug zum Konfigurieren von Drahtlos-Netzwerkgeräten unter Linux
iproute2 V:701, I:949 3294 config::iproute2 iproute2, IPv6 und andere erweiterte Netzwerkkonfiguration: ip(8), tc(8) usw.
iptables V:306, I:942 2521 config::Netfilter Administrationswerkzeuge für Paketfilterung und NAT (Netfilter)
iputils-ping V:206, I:997 118 Test Erreichbarkeit eines fernen Rechners über das Netzwerk testen, entweder mittels Rechnername oder IP-Addresse (iproute2)
iputils-arping V:5, I:78 60 Test Erreichbarkeit eines fernen Rechners über das Netzwerk mittels seiner ARP-Addresse testen
iputils-tracepath V:4, I:46 52 Test Netzwerkpfad zu einem fernen Rechner verfolgen
ethtool V:96, I:267 631 Test Eigenschaften von Ethernet-Geräten anzeigen oder ändern
mtr-tiny V:6, I:52 161 test::low-level Netzwerkpfad zu einem fernen Rechner verfolgen (Curses-basiert)
mtr V:4, I:44 214 " Netzwerkpfad zu einem fernen Rechner verfolgen (Curses- und GTK-basiert)
gnome-nettool V:1, I:31 2110 " Werkzeuge für allgemeine Netzwerkinformations-Operationen (GNOME)
nmap V:28, I:231 4452 " Netzwerk-Mapper/Port-Scanner (Nmap, konsolen-basiert)
zenmap V:0, I:4 2939 " Netzwerk-Mapper/Port-Scanner (GTK-basiert)
tcpdump V:18, I:196 1330 " Netzwerkverkehr-Analysator (Tcpdump, konsolen-basiert)
wireshark I:52 72 " Netzwerkverkehr-Analysator (Wireshark, GTK-basiert)
tshark V:2, I:30 427 " Netzwerkverkehr-Analysator (konsolen-basiert)
tcptrace V:0, I:2 401 " eine Zusammenfassung von Verbindungen auf Basis der tcpdump-Ausgabe erstellen
snort V:0, I:1 2206 " flexibles Einbruchmeldesystem für das Netzwerk (Snort)
ntopng V:1, I:1 969 " Daten über die Netzwerknutzung im Webbrowser anzeigen
dnsutils V:39, I:423 275 " Netzwerk-Clients, die mit BIND bereitgestellt werden: nslookup(8), nsupdate(8), dig(8)
dlint V:0, I:5 53 " DNS-Zoneninformationen mittels Nameserver-Abfragen überprüfen
dnstracer V:0, I:1 60 " eine Verkettung von DNS-Servern zu ihrer Quelle verfolgen


Die Auflösung des Rechnernamens

Die Auflösung des Rechnernamens (hostname) wird derzeit auch durch den NSS-(Name-Service-Switch-)Mechanismus unterstützt. Die Auflösung läuft wie folgt ab:# Die "/etc/nsswitch.conf"-Datei mit Einträgen wie "hosts: files dns" bestimmt die Reihenfolge der Rechnernamenauflösung. (Dies ersetzt die alte Funktionalität der "order"-Einträge in "/etc/host.conf".)

  1. Als erstes wird in diesem Beispiel die files-Methode aufgerufen. Wenn der Rechnername in der "/etc/hosts"-Datei gefunden wird, werden alle gültigen Adressen für den Rechner ausgegeben und die Abfrage wird beendet. (Die "/etc/host.conf"-Datei enthält "multi on".)
  2. Dann wird die dns-Methode wird aufgerufen. Wenn der Rechnername über das Internet Domain Name System (DNS) (definiert über die Datei "/etc/resolv.conf") gefunden wird, werden alle dafür gültigen Adressen ausgegeben und die Abfrage wird beendet.

Die "/etc/hosts"-Datei sieht zum Beispiel so aus:

127.0.0.1 localhost
127.0.1.1 host_name
# The following lines are desirable for IPv6 capable hosts
::1 localhost ip6-localhost ip6-loopback
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters

Jede Zeile beginnt mit einer IP-Addresse und dahinter steht jeweils der zugeordnete Rechnername.

Die IP-Adresse 127.0.1.1 in der zweiten Zeile dieses Beispiels ist auf einigen anderen Unix-ähnlichen Systemen möglicherweise nicht vorhanden. Der Debian Installer erstellt diesen Eintrag für Systeme ohne feste IP-Adresse als provisorische Lösung für einige Software-Produkte (z.B. GNOME), wie in Fehler #719621 dokumentiert.

Der Eintrag rechnername entspricht dem in"/etc/hostname" festgelegten Rechnernamen.

Auf Systemen mit einer festen IP-Adresse sollte allerdings diese feste IP-Adresse statt der 127.0.1.1 verwendet werden.

Bei Systemen mit einer festen IP-Adresse und einem voll qualifizierten Domain-Namen (FQDN), bereitgestellt durch das Domain Name System (DNS), sollte rechnername.domain-name verwendet werden statt nur rechnername.

Die Datei "/etc/resolv.conf" ist eine statische Datei, falls das Paket resolvconf nicht installiert ist. Falls das Paket installiert ist, ist dies ein symbolischer Link. In beiden Fällen enthält es Informationen zur Initialisierung der Namensauflösungs-Routinen. Wenn das DNS zum Beispiel über die IP "192.168.11.1" erreichbar ist, enthält sie Folgendes:

nameserver 192.168.11.1

Das resolvconf-Paket macht "/etc/resolv.conf" zu einem symbolischen Link und verwaltet ihren Inhalt automatisch über die Hook-Skripte.

Bei PC-Arbeitsplatzrechnern in einer typischen LAN-Umgebung kann der Rechnername zusätzlich zu den grundlegenden files- und dns-Methoden auch über Multicast DNS (mDNS, Zeroconf) aufgelöst werden:* Avahi stellt ein Rahmenwerk für Multicast-DNS-Diensteabfragen auf Debian-Systemen bereit.

  • Es ist ein Äquivalent zu Apple Bonjour / Apple Rendezvous.
  • Das libnss-mdns-Plugin-Paket bietet Rechnernamensauflösung via mDNS für die GNU Name-Service-Switch-(NSS-)Funktionalität der GNU C-Bibliothek (glibc).
  • Die Datei "/etc/nsswitch.conf" sollte Einträge wie "hosts: files mdns4_minimal [NOTFOUND=return] dns mdns4" enthalten.
  • Rechnernamen, die mit der Pseudo-Top-Level Domain (TLD) ".local" enden, werden aufgelöst.
  • Die mDNS IPv4 link-lokale Multicast-Adresse "224.0.0.251" oder ihr IPv6-Äquivalent "FF02::FB" wird verwendet, um DNS-Abfragen für einen auf ".local" endenden Namen durchzuführen.

Rechnernamensauflösung über das veraltete NETBios over TCP/IP, das von älteren Windows-Systemen verwendet wurde, kann über die Installation des Pakets winbind realisiert werden. Die "/etc/nsswitch.conf"-Datei sollte Einträge wie "hosts: files mdns4_minimal [NOTFOUND=return] dns mdns4 wins" enthalten, um diese Funktionalität zu aktivieren. (Moderne Windows-Systeme verwenden normalerweise die dns-Methode zur Rechnernamensauflösung.)

"[Anmerkung]" Anmerkung
Die Ausweitung generischer Top-Level-Domains (gTLD) im Domain-Name-System ist in Arbeit. Achten Sie bei Auswahl von Domain-Namen, die nur im lokalen Netzwerk verwendet werden sollen, auf Namenskollisionen.

Der Netzwerkschnittstellenname

Systemd verwendet "verlässlich vorhersagbare Namen (Predictable Network Interface Names)" wie "enp0s25".


Der Netzwerkadressbereich für das LAN

Wir wollen uns an die IPv4 32-Bit-Adressbereiche erinnern, die durch die rfc1918 für jede Klasse zur Verwendung in Local Area Networks (LANs) reserviert sind. Diese Adressen werden bestimmt nicht mit irgendwelchen Adressen im Internet kollidieren.

"[Anmerkung]" Anmerkung
IP-Adressen mit Doppelpunkten sind IPv6-Adressen, z.B. "::1" für localhost.
Liste der Netzwerkadressbereiche
Klasse Netzwerkadressen Netzmaske Netzmaske /Bits von Subnetzwerken
A 10.x.x.x 255.0.0.0 /8 1
B 172.16.x.x — 172.31.x.x 255.255.0.0 /16 16
C 192.168.0.x — 192.168.255.x 255.255.255.0 /24 256
"[Anmerkung]" Anmerkung
Wenn eine dieser Adressen einem Rechner zugewiesen ist, kann dieser Rechner das Internet nicht direkt erreichen, sondern muss ein Gateway verwenden, der als Proxy für verschiedene Dienste dient, oder er nutzt Network Address Translation (NAT). Ein Breitband-Router nutzt üblicherweise NAT für das Anwender-Netzwerk.

Unterstützung für Netzwerkgeräte

Der größte Teil verfügbarer Netzwerk-Hardware wird durch das Debian-System unterstützt; es gibt einige Geräte, die laut DFSG nicht-freie Firmware für den Betrieb erfordern. Lesen Sie dazu Abschnitt 9.10.5, „Hardware-Treiber und Firmware“.


Moderne Netzwerkkonfiguration für Arbeitsplatzsysteme

Auf modernen Debian-Desktop-Systemen mit systemd erfolgt die Initialisierung von Netzwerkschnittstellen für die Loopback-Schnittstelle lo typischerweise durch "networking.service" und für andere Schnittstellen durch "NetworkManager.service".

Debian-Systeme können Netzwerkverbindungen über Software-Daemons wie NetworkManager (NM) (network-manager und zugehörige Pakete) verwalten.* Sie haben ihre eigenen grafischen GUI- und Befehlszeilen-Programme als Bedienoberfläche.

  • Sie haben ihre eigenen Daemons als Unterbau.
  • Sie erlauben eine einfache Verbindung Ihres Systems mit dem Internet.
  • Sie ermöglichen eine problemlose Verwaltung von kabelgebundenen und kabellosen Netzwerkkonfigurationen.
  • Sie erlauben uns, das Netzwerk unabhängig vom althergebrachten ifupdown zu konfigurieren.
"[Anmerkung]" Anmerkung
Verwenden Sie diese automatischen Netzwerkkonfigurations-Werkzeuge nicht für Server. Sie sind primär für die Nutzung auf Arbeitsplatzrechnern oder Laptops gedacht.

Diese modernen Werkzeuge müssen korrekt konfiguriert werden, um Konflikte mit dem ifupdown-Paket und seiner Konfigurationsdatei "/etc/network/interfaces" zu vermeiden.


Grafische Netzwerkkonfigurations-Werkzeuge

Offizielle Dokumentation für NM unter Debian ist in "/usr/share/doc/network-manager/README.Debian" verfügbar.

Grundsätzlich läuft die Netzwerkkonfiguration für Arbeitsplatzsysteme wie folgt ab:# Fügen Sie den Benutzer, der sich am Arbeitsplatz anmeldet, z.B. foo, mit folgendem Befehl zur Gruppe "netdev" hinzu (alternativ kann dies in modernen Arbeitsplatzumgebungen wie GNOME oder KDE auch automatisch über D-bus erledigt werden):
$ sudo adduser foo netdev

  1. Halten Sie die Konfiguration in "/etc/network/interfaces" so einfach wie hier:
    auto lo
    iface lo inet loopback
  2. Starten Sie NM mit folgendem Befehl neu:
    $ sudo systemctl restart network-manager
  3. Konfigurieren Sie Ihr Netzwerk über die grafische GUI-Oberfläche.
"[Anmerkung]" Anmerkung
Um Konflikte mit ifupdown zu vermeiden, werden nur Schnittstellen, die nicht in "/etc/network/interfaces" aufgelistet sind, von NM verwaltet.
"[Tipp]" Tipp
Wenn Sie die Fähigkeiten von NM erweitern möchten, suchen Sie nach entsprechenden Plugin-Modulen und zusätzlichen Paketen wie network-manager-openconnect, network-manager-openvpn-gnome, network-manager-pptp-gnome, mobile-broadband-provider-info, gnome-bluetooth usw.

Moderne Netzwerkkonfiguration ohne grafische Oberfläche

Unter systemd kann das Netzwerk stattdessen in /etc/systemd/network/ konfiguriert werden. Lesen Sie dazu systemd-resolved(8), resolved.conf(5) und systemd-networkd(8).

Dies ermöglicht eine moderne Netzwerkkonfiguration auch ohne grafische Oberfläche.

Eine DHCP-Client-Konfiguration kann durch Erzeugen von "/etc/systemd/network/dhcp.network" eingerichtet werden, z.B. mit:

[Match]
Name=en*
[Network]
DHCP=yes

Eine statische Netzwerkkonfiguration richten Sie über "/etc/systemd/network/static.network" ein, wie hier:

[Match]
Name=en*
[Network]
Address=192.168.0.15/24
Gateway=192.168.0.1


Netzwerkkonfiguration auf unterster Ebene

Für Netzwerkkonfiguration über die Konsole können Sie unter Linux die iproute2-Programme (ip(8), …) verwenden.


iproute2-Befehle

Die iproute2-Befehle bieten vollwertige Funktionalität auf der untersten Ebene der Netzwerkkonfiguration. Hier eine Tabelle zur Gegenüberstellung von veralteten net-tools-Befehlen und neuen iproute2- und anderen Befehlen.

Gegenüberstellung von net-tools- und iproute2-Befehlen
net-tools (veraltet) iproute2 usw. (neu) Beeinflussung
ifconfig(8) ip addr Protokoll-Adresse (IP oder IPv6) eines Gerätes
route(8) ip route Eintrag in der Routing-Tabelle
arp(8) ip neigh ARP- oder NDISC-Cache-Eintrag
ipmaddr ip maddr Multicast-Adresse
iptunnel ip tunnel Tunnel über IP
nameif(8) ifrename(8) Netzwerkschnittstellen basierend auf MAC-Adressen benennen
mii-tool(8) ethtool(8) Einstellungen von Ethernet-Geräten

Lesen Sie ip(8) und das IPROUTE2 Utility Suite Howto.


Sichere Basis-Netzwerkoperationen

Sie können die folgenden Netzwerkbefehle der untersten Ebene problemlos verwenden, da sie die Netzwerkkonfiguration nicht verändern:

Tabelle 5.4. Liste von Basis-Netzwerkbefehlen
Befehl Beschreibung
ip addr show Verbindungs- und Adressstatus von aktiven Schnittstellen anzeigen
route -n Vollständige Routing-Tabelle mit numerischen Adressen anzeigen
ip route show Vollständige Routing-Tabelle mit numerischen Adressen anzeigen
arp Aktuellen Inhalt der ARP-Cache-Tabellen anzeigen
ip neigh Aktuellen Inhalt der ARP-Cache-Tabellen anzeigen
plog Logdaten des PPP-Daemons anzeigen
ping yahoo.com Internet-Verbindung zu "yahoo.com" überprüfen
whois yahoo.com Überprüfen, wer "yahoo.com" in der Domain-Datenbank registriert hat
traceroute yahoo.com Verbindung zu "yahoo.com" durch das Internet verfolgen
tracepath yahoo.com Verbindung zu "yahoo.com" durch das Internet verfolgen
mtr yahoo.com Verbindung zu "yahoo.com" durch das Internet verfolgen (wiederholt)
dig [@dns-server.com] example.com [{a|mx|any}] DNS-Einträge von "example.com" laut den Daten von "dns-server.com" auf einen "a"-, "mx"- oder "any"-Eintrag überprüfen
iptables -L -n Paketfilter überprüfen
netstat -a Alle offenen Ports finden
netstat -l --inet Ports finden, die auf eine Verbindung warten
netstat -ln --tcp TCP-Ports finden, die auf eine Verbindung warten (numerisch)
dlint example.com DNS-Zonen-Informationen von "example.com" überprüfen
"[Tipp]" Tipp
Einige dieser Basisbefehle zur Netzwerkkonfiguration sind in "/sbin/" abgelegt. Sie müssen unter Umständen den vollständigen Pfad, wie z.B. "/sbin/ifconfig" angeben oder "/sbin" zur Variable "$PATH" in Ihrer "~/.bashrc"-Datei hinzufügen.

Netzwerkoptimierung

Die grundsätzliche Netzwerkoptimierung liegt außerhalb des Rahmens dieser Dokumentation. Ich erwähne hier nur Dinge, die für Anwender-typische Verbindungen passend sind.

Liste von Werkzeugen zur Netzwerkoptimierung
Pakete Popcon Größe Beschreibung
iftop V:7, I:112 97 Informationen zur Bandbreitennutzung einer Netzwerkschnittstelle anzeigen
iperf V:3, I:52 322 Werkzeug zur IP-Bandbreiten-Messung
ifstat V:0, I:8 59 InterFace STATistics Monitoring (Netzwerkschnittstellen-Statistik/-Überwachung)
bmon V:1, I:17 146 Portierbarer Bandbreitenmonitor und Geschwindigkeitsrechner
ethstatus V:0, I:4 40 Skript, das schnell den Durchsatz eines Netzwerkgerätes messen kann
bing V:0, I:1 80 Empirisch stochastischer Bandbreitentester
bwm-ng V:1, I:17 90 Kleiner und einfacher konsolenbasierter Bandbreitenmonitor
ethstats V:0, I:0 23 Konsolenbasierter Ethernet-Statistikmonitor
ipfm V:0, I:0 78 Bandbreitenanalyse-Werkzeug


Die optimale MTU finden

NM setzt den optimalen Wert für die Maximum Transmission Unit (MTU) normalerweise automatisch.

In speziellen Fällen möchten Sie die MTU jedoch vielleicht händisch setzen, nachdem Sie mit ping(8) und seiner Option "-M do" experimentiert haben; Sie haben damit die Möglichkeit, ein ICMP-Paket mit verschiedenen Paketgrößen zu verschicken. MTU ist die größte Paketgröße, bei der das Paket noch erfolgreich ohne Fragmentierung verschickt werden kann plus 28 Byte für die IPv4- bzw. 48 Byte für die IPv6-Adresse. In folgendem Beispiel wurde für eine IPv4-Verbindung eine MTU von 1460 ermittelt und für IPv6 eine MTU von 1500:

$ ping -4 -c 1 -s $((1500-28)) -M do www.debian.org
PING (149.20.4.15) 1472(1500) bytes of data.
ping: local error: message too long, mtu=1460

--- ping statistics ---
1 packets transmitted, 0 received, +1 errors, 100% packet loss, time 0ms
$ ping -4 -c 1 -s $((1460-28)) -M do www.debian.org
PING (130.89.148.77) 1432(1460) bytes of data.
1440 bytes from klecker-misc.debian.org (130.89.148.77): icmp_seq=1 ttl=50 time=325 ms

--- ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 325.318/325.318/325.318/0.000 ms
$ ping -6 -c 1 -s $((1500-48)) -M do www.debian.org
PING www.debian.org(mirror-csail.debian.org (2603:400a:ffff:bb8::801f:3e)) 1452 data bytes
1460 bytes from mirror-csail.debian.org (2603:400a:ffff:bb8::801f:3e): icmp_seq=1 ttl=47 time=191 ms

--- www.debian.org ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 191.332/191.332/191.332/0.000 ms

Dies ist das Path MTU (PMTU) Discovery-Verfahren (RFC1191) und der Befehl tracepath(8) kann dies automatisieren.

Wesentliche Grundregeln für den optimalen MTU-Wert
Netzwerkumgebung MTU Argumentation
Einwahlverbindung (IP: PPP) 576 Standard
Ethernet-Verbindung (IP: DHCP oder fest) 1500 Standard und vorgegeben

Zusätzlich zu diesen Grundregeln sollten Sie folgendes wissen:

  • Jegliche Nutzung von Tunneling-Methoden (VPN usw.) kann aufgrund des Overheads den optimalen MTU-Wert reduzieren.
  • Der MTU-Wert sollte den über die experimentelle Methode ermittelten PMTU-Wert nicht überschreiten.
  • Ein größerer MTU-Wert ist grundsätzlich besser, wenn andere Einschränkungen greifen.

Die Maximum Segment Size (MSS) wird als alternative Messmethode für die Paketgröße verwendet. Der Zusammenhang zwischen MSS und MTU ist wie folgt:

  • MSS = "MTU - 40" bei IPv4
  • MSS = "MTU - 60" bei IPv6
"[Anmerkung]" Anmerkung
Bei Netzwerkoptimierung mittels iptables(8) (lesen Sie dazu auch Abschnitt 5.6, „Die Netfilter-Infrastruktur“) kann die Paketgröße über die MSS begrenzt werden; dies ist für einen Router nützlich. Lesen Sie den Abschnitt bezüglich "TCPMSS" in iptables(8).

WAN-TCP-Optimierung

Der TCP-Durchsatz kann über die Anpassung von Parametern zur TCP-Puffergröße maximiert werden, wie es die Anleitungen "TCP Tuning Guide" und "TCP Tuning" für modernes WAN mit hoher Bandbreite und hoher Latenz beschreiben. Das soll hierzu genügen; die aktuellen Debian-Standardeinstellungen funktionieren für mein LAN mit seiner Verbindung zum sehr schnellen 1G bps FFTP-Dienst sehr gut.


Die Netfilter-Infrastruktur

Netfilter stellt eine Infrastruktur für Stateful Packet Inspection (SPI, zustandsorientierte Paketüberprüfung) und Network Address Translation (NAT) über Module des Linux-Kernels (lesen Sie hierzu Abschnitt 3.8.1, „Die Kernel-Modul-Initialisierung“) zur Verfügung.

Liste von Firewall-Werkzeugen
Pakete Popcon Größe Beschreibung
iptables V:306, I:942 2521 Administrationswerkzeuge für netfilter (iptables(8) für IPv4, ip6tables(8) für IPv6)
arptables V:0, I:2 96 Administrationswerkzeuge für netfilter (arptables(8) für ARP)
ebtables V:14, I:33 265 Administrationswerkzeuge für netfilter (ebtables(8) für Ethernet-Bridging-Betrieb)
iptstate V:0, I:3 116 Fortlaufende Überwachung des netfilter-Status (ähnlich zu top(1))
shorewall-init V:0, I:0 68 Initialisierung der Shoreline Firewall
shorewall V:5, I:11 2458 Erzeugung von netfilter-Konfigurationsdateien für Shoreline Firewall
shorewall-lite V:0, I:0 65 Erzeugung von netfilter-Konfigurationsdateien für Shoreline Firewall (abgespeckte Version)
shorewall6 V:1, I:2 779 Erzeugung von netfilter-Konfigurationsdateien für Shoreline Firewall (IPv6-Version)
shorewall6-lite V:0, I:0 64 Erzeugung von netfilter-Konfigurationsdateien für Shoreline Firewall (abgespeckte IPv6-Version)

Das vorherrschende Nutzerprogramm für netfilter ist iptables(8). Sie können netfilter von Hand interaktiv über die Shell konfigurieren, seinen Status mit iptables-save(8) sichern und beim Systemstart über ein Init-Skript mittels iptables-restore(8) wiederherstellen.

Konfigurations-Hilfsskripte wie shorewall vereinfachen diesen Prozess.

Sie finden Dokumentation unter http://www.netfilter.org/documentation/ oder in "/usr/share/doc/iptables/html/":* Linux Networking-Concepts HOWTO

"[Tipp]" Tipp
Obwohl für Linux 2.4 geschrieben, sind sowohl der iptables(8)-Befehl wie auch die Netfilter-Kernel-Funktionalität für die Linux-Kernel-Serien 2.6 und 3.x passend.

Quelle: https://www.debian.org/doc/manuals/debian-reference/ch05.de.html


All About Debian /etc/network/interfaces File

by David AdamsThe 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/

3 ways to configure the network

  • The interfaces configuration file at /etc/network/interfaces (this page): for basic or simple configurations (e.g. workstation)
  • NetworkManager: This is the default for Laptop configuration
  • Systemd: Debian reference Doc Chapter 5


Setting up an Ethernet Interface

The majority of network setup can be done via the interfaces configuration file at /etc/network/interfaces. Here, you can give your network card an IP address (or use dhcp), set up routing information, configure IP masquerading, set default routes and much more.

Remember to add interfaces that you want brought up at boot time to the 'auto' line.

See man interfaces for more options.


Starting and Stopping Interfaces

Interfaces configured with /etc/network/interfaces can be brought up and down with the ifup and ifdown commands.

Some outdated guides instruct to restart the networking service to apply changes to /etc/network/interfaces, however this was deprecated because it is possible that not all interfaces will be restarted. Instead use ifup and ifdown to apply changes to each interface, for example with an interface named enp7s0:

# ifdown enp7s0
# ifup enp7s0


Reinitialize new network setup

If you make more fundamental network changes e.g. adding new virtual interfaces (e.g. bridge) in /etc/network/interfaces you can reinitialize the network-configuration be restarting the networking daemon:

# systemctl status networking
# systemctl restart networking


Network Interface Names

See NetworkInterfaceNames. Since Stretch, new systems by default no longer use old-style interface names such as eth0, eth1, wlan0, wlan1. The new system uses names based on hardware location, like eno0, enp0s31f6, wlp1s7 (or in the case of USB dongles, MAC address: enx2c56ac39ec0d).

You can list interfaces with: ls /sys/class/net

Various examples below continue to use "eth0" as a default interface name, even though it is unlikely to exist on a modern system.


Upgrading and Network Interface Names

Stretch and Buster still retain support for the old naming system as long as the file /etc/udev/rules.d/70-local-persistent-net.rules is still in place, but users are advised to switch ahead of the upgrade to Bullseye.


Using DHCP to automatically configure the interface

If you're just using DHCP then all you need is something like:

auto eth0
allow-hotplug eth0
iface eth0 inet dhcp

For DHCPv6 (used for IPv6), append also the following iface stanza

iface eth0 inet6 dhcp

Alternatively, IPv6 can be autoconfigured using stateless address autoconfiguration, or SLAAC, which is specified using auto instead of dhcp in the inet6 stanza:

iface eth0 inet6 auto

Also see IPv6PrefixDelegation.


Configuring the interface manually

If you're configuring it manually then something like this will set the default gateway (network, broadcast and gateway are optional):

auto eth0
iface eth0 inet static
address 192.0.2.7/24
gateway 192.0.2.254

If you want to add an IPv6 address, too, append something like:

iface eth0 inet6 static
address 2001:db8::c0ca:1eaf/64
gateway 2001:db8::1ead:ed:beef

See man interfaces for more options.

Make sure to disable all DHCP services, e.g. dhcpcd.

Mixing manual and automatic configuration is also possible, e.g. to use IPv6 SLAAC for internet connectivity and static addresses within the network:

  1. manual unique local address
iface eth0 inet6 static
 address fdc3:cafe::3/64
 # use SLAAC to get global IPv6 address from the router
 # we may not enable ipv6 forwarding, otherwise SLAAC gets disabled
 autoconf 1
 accept_ra 2


Setting the speed and duplex

Autonegotiation repeatedly failing is often a symptom of faulty cabling, so investigate physical matters before assuming that the interfaces' autonegotiation algorithms are incompatible. If you turn off autonegotiation and set speed and duplex manually then the partner interface at the other end of the cable will assume that the absence of autonegotiation indicates a speed of 10Mbps and a duplex of half. For error-free operation if you set speed and duplex manually you must ensure that exactly the same speed and duplex are configured on the partner interface.

If you set your interface's speed and duplex by hand, then some trial and error may be required. Here are the basic steps: * Install the ethtool and net-tools packages, so that you have the ethtool and mii-tool programs. One or both of these might work for your interface.

  • Make sure you have a way to login to the system in case the network interface becomes nonfunctional. An SSH connection could be disrupted, so you should have a fallback strategy.
  • Identify the interface in question (it will often be eth0). Adjust the remainder of these instructions accordingly.
  • Try to determine what its current speed and duplex settings are. This is where it gets fun:
    • As root, try ethtool eth0 first, and see whether the "Speed:" and "Duplex:" lines look valid. If not, the ethtool may not be supported by your device.
    • As root, try mii-tool -v eth0 and see whether its output looks correct. If not, them mii-tool may not be supported by your device.
    • If neither one is supported, you may have to set parameters directly on the kernel driver module. Identify which driver module you're using by reading the output of dmesg and lsmod. You can then try modinfo MODULENAME to see what parameters it accepts, if any. (You can use modinfo even on modules that are not loaded, for comparison.) ToDo: where does one set kernel module parameters?
  • Next, try to change the settings of the interface while it's operating. You'll need to be root, of course. Either:
    • ethtool -s eth0 speed 100 duplex full autoneg off (assuming 100 Mbps and full duplex)
    • mii-tool -F 100baseTx-FD eth0 (same assumption)

In each case, re-check to see whether the interface settings actually changed, and then try sending some data in and out of the system to see whether the NIC is operating correctly.

  • If one of these commands successfully set your NIC, then you can put it into /etc/network/interfaces so it runs when you bring the interface up (e.g. at boot time). However, before you do that, you should understand that some drivers and devices behave differently than others. When the driver module is loaded, the NIC may begin autonegotiation without any way to stop it (particularly with drivers that do not accept parameters). The settings from interfaces are applied at some point after that, which may be right in the middle of the negotiation. So, some people find it necessary to delay the ethtool or mii-tool command by a few seconds. Thus:
    iface eth0 inet static
    address .../...
    gateway ...
    up sleep 5; ethtool -s eth0 ...
    Or the analogous mii-tool command.
  • Reboot the machine to make sure it comes up correctly, and be prepared to intervene manually (e.g. Ctrl-Alt-Del and then boot into single-user mode from GRUB or LILO) if things don't work.


Bringing up an interface without an IP address

To create a network interface without an IP address at all use the manual method and use pre-up and post-down commands to bring the interface up and down.

iface eth0 inet manual
pre-up ifconfig $IFACE up
post-down ifconfig $IFACE down

If the interface is a VLAN interface, the up/down commands must be executed after/before the vlan hooks. (You also have to install the vlan package.)

iface eth0.99 inet manual
post-up ifconfig $IFACE up
pre-down ifconfig $IFACE down

Note: If you create the VLAN interface only to put it into a bridge, there is no need to define the VLAN interface manually. Just configure the bridge, and the VLAN interface will be created automatically when creating the bridge (see below).


Defining the (DNS) Nameservers

Before a computer can connect to an external network resource (say, for example, a web server), it must have a means of converting any alpha-numeric names (e.g. wiki.debian.org) into numeric network addresses (e.g. 140.211.166.4). (The Internet uses these structured numeric IP addresses as network addresses.)

The C library and other resolver libraries look to /etc/resolv.conf for a list of nameservers. In the simplest case, that is the file to edit to set the list of name servers. But note that various other programs for dynamic configuration will be happy to overwrite your settings: # The resolvconf program

  1. The network-manager daemon
  2. DHCP clients

In most situations, the file to edit is the configuration file for such a program.

In the most complex situations, using resolvconf really is the way to go, though in more simple configurations it is probably overkill.


The resolv.conf configuration file

The configuration file resolv.conf at /etc/resolv.conf contains information that allows a computer connected to a network to resolve names into addresses. (Note: Do not confuse this configuration file with the program resolvconf, which unfortunately has a nearly identical name.)

The resolv.conf file typically contains the IP addresses of nameservers (DNS name resolvers) that will attempt to translate names into addresses for any node available on the network. There will be a line or lines that look like this:

nameserver 12.34.56.78
nameserver 12.34.56.79

In this example, the system is using nameservers at the IP addresses 12.34.56.78 and 12.34.56.79. Simply edit the file and enter the IP addresses of the nameservers you need to use after each nameserver. Add more nameserver lines if you have more nameservers. Don't use this method if you have the resolvconf program installed.

The resolv.conf configuration file has many other options for defining how resolver looks up names. See man resolv.conf for details.


The resolvconf program

The resolvconf program keeps track of system information about the currently available nameservers. It should not be confused with the configuration file resolv.conf, which unfortunately has a nearly identical name. The resolvconf program is optional on a Debian system.

The configuration file resolv.conf contains information about the nameservers to be used by the system. However, when multiple programs need to dynamically modify the resolv.conf configuration file they can step on each other and the file can become out-of-sync. The resolvconf program addresses this problem. It acts as an intermediary between programs that supply nameserver information (e.g. dhcp clients) and programs that use nameserver information (e.g. resolver).

When resolvconf is properly installed, the resolv.conf configuration file at /etc/resolv.conf is replaced by a symbolic link to /etc/resolvconf/run/resolv.conf and the resolver instead uses the configuration file that is dynamically generated by resolvconf at /etc/resolvconf/run/resolv.conf.

The resolvconf program is generally only necessary when a system has multiple programs that need to dynamically modify the nameserver information. In a simple system where the nameservers do not change often or are only changed by one program, the resolv.conf configuration file is adequate.

If the resolvconf program is installed, you should not edit the resolv.conf configuration file manually as it will be dynamically changed by programs in the system. If you need to manually define the nameservers (as with a static interface), add a line something like the following to the interfaces configuration file at /etc/network/interfaces:

dns-nameservers 12.34.56.78 12.34.56.79

Place the line indented within an iface stanza, e.g., right after the gateway line. Enter the IP addresses of the nameservers you need to use after dns-nameservers. Put all of them on one line separated by spaces. Don't forget the "s" on the end of dns-nameservers.

The resolvconf program is a fairly new addition to Debian and many older programs need to be updated or reconfigured to work properly with it. If you have problems, see /usr/share/doc/resolvconf/README. It has lots of information on making other programs get along with resolvconf.


DNS configuration for NetworkManager

NetworkManager will override dhcp settings, overwriting resolv.conf even if you've configured DNS in /etc/dhcp/dhclient.conf, e.g. causing DNS to first search the local domain, which may have to time out before DNS resolution continues causing lengthy DNS resolution times. You can get an idea of what NetworkManager thinks the settings should be by executing nm-tool at the command line.

You may configure these settings using a GUI by launching nm-connection-editor which currently (13.11.23) isn't to be found in System Tools → Administration menu, rather it must be launched by hand from the command line. After launching: # Choose a connection (from the Wired or Wireless tab) and click Edit.

  1. Click on the IPv4 Settings tab
  2. Choose 'Automatic (DHCP) addresses only' instead of just 'Automatic (DHCP)'.
  3. Enter the DNS servers in the “DNS servers” field, separated by spaces (e.g. 208.67.222.222 for OpenDNS).
  4. Click “Apply.”

NetworkManager saves these settings in /etc/NetworkManager/system-connections/name-of-connection. Example /etc/NetworkManager/system-connections/Wired connection 1 :

[802-3-ethernet]
duplex=full
mac-address=XX:XX:XX:XX:XX:XX

[connection]
id=Wired connection 1
uuid=xxx-xxxxxx-xxxxxx-xxxxxx-xxx
type=802-3-ethernet
timestamp=1385213042

[ipv6]
method=auto

[ipv4]
method=auto
dns=208.67.222.222;
ignore-auto-dns=true

Running nm-tool again should show that NetworkManager now has the right idea of how your DNS should be resolved.


DHCP Client Configuration

Setting additional DNS Servers

Example: dhclient3 uses /etc/dhcp/dhclient.conf. The setting you want is

supersede domain-name-servers 12.34.56.78, 12.34.56.79;

or perhaps

prepend domain-name-servers 12.34.56.78, 12.34.56.79;


Setting additional search domains

adding search domains for VPNs or local virtual networks:

append domain-name " virt vpn";

Note the leading space since the string is literally appended to the search domain provided by other configurations.

See the dhclient.conf(5) manual page for details.


Bridging

Bridging puts multiple interfaces into the same network segment. This is very popular when connecting a server to multiple switches for high availability or with virtualization. In the latter case it is usually used to create a bridge in the host (eg. dom0) and put the virtual interfaces of the guests (domU) into the bridge. * The bridge-utils package is required to create bridged interfaces.

Example: Connect a server to 2 switches (via eth0 and eth1) by defining bridge 0 and give the server an IP address in this subnet:

auto br0
iface br0 inet static
 address 10.10.0.15/24
 gateway 10.10.0.1
 bridge_ports eth0 eth1
 up /usr/sbin/brctl stp br0 on

If a server is connected to multiple switches then you usually need to run the spanning tree protocol to avoid loops. Therefore STP must be turned on via an "up" command as shown above.

Example: Bridge setup without IP address configuration (use "manual" instead of "static") to "forward" an interface to a guest VM. (The static bridge config contains only 1 physical interface. The virtual interface will be added to the bridge when the VM is started.)

auto br1
iface br1 inet manual
 bridge_ports eth4
 up /usr/sbin/brctl setageing br1 0
 up /usr/sbin/brctl stp br1 off

Note: The Linux bridge supports only STP, no RSTP (Rapid Spanning Tree). Therefore it supports only the old STP Costs, not the new RSTP Costs (see Spanning_Tree_Protocol). This is usually fine with Cisco Switches, but eg. Juniper switches use the RSTP costs and therefore this may lead to different spanning tree calculations and loop problems. This can be fixed by settings the costs manually, either on the switch or on the server. Setting the cost on the switch is preferred as Linux switches back to the default costs whenever an interface does down/up.


Bridging without Switching

By default the Linux bridge acts like a switch. This means, it remembers the MAC addresses behind a switch port and if the destination MAC address is known, data packets or only forward to the respective port - otherwise packets will be broadcasted.

In some setups this is bad. For example if the bridge connects 2 trunk interfaces and the same MAC addresses may be seen from both interfaces, depending on the VLAN. As the Linux bridge does not support VLANs (dedicated MAC address tables per each VLAN), in such setups you have to disable the MAC address learning and put the bridge into a real "bridge" mode with:

up /sbin/brctl setageing br0 0
up /sbin/brctl stp br0 off


Howto use vlan (dot1q, 802.1q, trunk) (Etch, Lenny)

Manual config

modprobe 8021q

apt install vlan

vconfig add eth0 222 # 222 is vlan number
ifconfig eth0.222 up
ifconfig eth0.222 mtu 1496 #optional if your network card doesn't support MTU 1504B
ifconfig eth0.222 10.10.10.1 netmask 255.255.255.0


Network init script config

Into /etc/modules add line:

8021q

In /etc/network/interfaces to section iface add parameter:

vlan-raw-device eth0

The interface name should be the raw interface name (the same as specified by vlan-raw-device), then a dot, then the VLAN ID, for example eth0.100. It can instead be "vlan" then the VLAN ID, for example vlan100. In either case, the VLAN ID is on the end, and this is the only place that it is configured.

Note: If you name your VLAN interfaces ethX.YYY, then there is no need to specify the vlan-raw-device, as the raw device can be retrieved from the interface name.

Eg:

auto eth0.222
iface eth0.222 inet static
 address 10.10.10.1/24
 vlan-raw-device eth0


Bridges and VLANs

If you create VLAN interfaces only to put them into a bridge, there is no need to define the VLAN interfaces manually. Just config the bridge, and the VLAN interface will be created automatically when creating the bridge, e.g:

auto br1
iface br1 inet manual
 bridge_ports eth0.99 eth1.99
 up /usr/sbin/brctl stp br1 on


Caveats when using bridging and vlan

#/etc/network/interfaces
auto eth0 bri0
iface eth0 inet static
 address 192.168.1.1/24
iface eth0.110 inet manual
 vlan-raw-device eth0
iface bri0 inet static
 address 192.168.110.1/24
 bridge_ports eth0.110
 bridge_stp on
 bridge_maxwait 10

If you are using a brigded VLAN setup, which is probably useful for networking in virtualization environments, take care to only attach either a bridge device or VLAN devices to an underlying physical device - like shown above. Attaching the physical interface (eth0) to a bridge (eg. bri1) while using the same physical interface on apparently different VLANs will result in all packets to remain tagged. (Kernel newer than 2.6.37 and older than 3.2).


Howto create fault tolerant bonding with vlan (Etch - Stretch)

"debian_bonding.png"

debian_bonding.dia

How to configure one of the above server active backup bonding 3 vlan {vlan10,vlan20,vlan30} Debian networking without SPOF without native vlan.

aptitude install vlan ifenslave-2.6


Network config

Cisco switch interface example config

interface GigabitEthernet1/2
 description eth1
 switchport
 switchport trunk encapsulation dot1q
 switchport trunk allowed vlan 10,20,30
 switchport mode trunk
 no ip address
 no cdp enable
 spanning-tree portfast trunk


bonding with active backup

Create a file /etc/modprobe.d/bonding.conf containing:

alias bond0 bonding
options bonding mode=active-backup miimon=100 downdelay=200 updelay=200 primary=eth1


/etc/network/interfaces

# The loopback network interface
auto lo
iface lo inet loopback
# The primary network interface
auto bond0
iface bond0 inet manual
 up ifconfig bond0 0.0.0.0 up
 slaves eth1 eth0
auto vlan10
iface vlan10 inet static
 address 10.10.10.12/24
 vlan-raw-device bond0
 gateway 10.10.0.1
 dns-search hup.hu
 dns-nameservers 10.10.0.2
auto vlan20
iface vlan20 inet static
 address 10.20.10.12/24
 vlan-raw-device bond0
auto vlan30
iface vlan30 inet static
 address 10.30.10.12/24
 vlan-raw-device bond0


How to set the MTU (Max transfer unit / packet size) with VLANS over a bonded interface

MTU needs to be configured on the bonding interface and slave interfaces after the reset of the configuration has been applied to the bonding interfaces. This is done using a post-up line in the bonding interface configuration.

auto bond0
iface bond0 inet manual
 up ifconfig lacptrunk0 0.0.0.0 up
 slaves eth0 eth1
# bond-mode 4 = 802.3ad
 bond-mode 4
 bond-miimon 100
 bond-downdelay 200
 bond-updelay 200
 bond-lacp-rate 1
 bond-xmit-hash-policy layer2+3
 post-up ifconfig eth0 mtu 9000 && ifconfig eth1 mtu 9000 && ifconfig bond0 mtu 9000

#vlan devices will use the MTU set on bond0 device
auto vlan101
iface vlan101 inet static

address 10.101.60.123/24
gateway 10.155.60.1
vlan-raw-device bond0

auto vlan151
iface vlan151 inet static

address 192.168.1.1/24
vlan-raw-device bond0


Multiple IP addresses on one Interface

Interface aliasing allows one interface to have multiple IP addresses. This is useful when more than one server is to be visible via the Internet. Note that virtual hosts can support multiple Apache servers with a single IP address. Apache responds to the domain name supplied by the client in the HTTP header. In many other situations, one external IP is needed for each server using a port.


Legacy method

This /etc/network/interfaces text assigns three IP addresses to eth0.

auto eth0
allow-hotplug eth0
iface eth0 inet static
 address 192.168.1.42/24
 gateway 192.168.1.1

auto eth0:0
allow-hotplug eth0:0
iface eth0:0 inet static
 address 192.168.1.43/24

auto eth0:1
allow-hotplug eth0:1
iface eth0:1 inet static
 address 192.168.1.44/24

An alias interface should not have "gateway" or "dns-nameservers"; dynamic IP assignment is permissible.

The above configuration is the previous traditional method that reflects the traditional use of ifconfig to configure network devices. ifconfig has introduced the concept of aliased or virtual interfaces. Those types of virtual interfaces have names of the form interface:integer and ifconfig treats them very similarly to real interfaces.

Nowadays ifupdown uses the ip utility from the iproute2 package instead of ifconfig. The newer ip utility does not use the same concept of aliases or virtual interfaces. However, it supports assigning arbitrary names to the interfaces (they're called labels). ifupdown uses this feature to support aliased interfaces while using ip.


iproute2 method

Also, ifupdown supports specifying multiple interfaces by repeating iface sections with the same interface name. The key difference from the method described above is that all such sections are treated by ifupdown as just one interface, so user can't add or remove them individually. However, up/down commands, as well as scripts, are called for every section as it used to be.

Note however that this method is dangerous! Certain driver/hardware combinations may sometimes fail to bring the link up if no labels are assigned to the alias interfaces. (Seen this on Debian Wheezy and Jessie with RTL8111/8168/8411 PCI Express Gigabit Ethernet Controller (rev 01) auto-negotiating to 10/full. A similar warning from another person exists in the history of this page.)

This /etc/network/interfaces text assigns three IP addresses to eth0.

auto eth0
allow-hotplug eth0
iface eth0 inet static
 address 192.168.1.42/24
 gateway 192.168.1.1
iface eth0 inet static
 address 192.168.1.43/24
iface eth0 inet static
 address 192.168.1.44/24
# adding IP addresses from different subnets is also possible
iface eth0 inet static
 address 10.10.10.14/24

Manual approach:

auto eth0
allow-hotplug eth0
iface eth0 inet static
 address 192.168.1.42/24
 gateway 192.168.1.1
 up ip addr add 192.168.1.43/24 dev $IFACE label $IFACE:0
 down ip addr del 192.168.1.43/24 dev $IFACE label $IFACE:0
 up ip addr add 192.168.1.44/24 dev $IFACE label $IFACE:1
 down ip addr del 192.168.1.44/24 dev $IFACE label $IFACE:1
 up ip addr add 10.10.10.14/24 dev $IFACE label $IFACE:2
 down ip addr del 10.10.10.14/24 dev $IFACE label $IFACE:2

Quelle: https://wiki.debian.org/NetworkConfiguration