debian:base-debian:networking-debian

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
debian:base-debian:networking-debian [2019/05/03 16:05] – [Netzwerk Konfiguration unter Debian / Ubuntu] michaeldebian:base-debian:networking-debian [2021/05/28 15:43] (current) – [Netzkonfiguration ab Ubuntu 18.04 / Debian X] michael
Line 3: Line 3:
 {{ :linux:linux_networking.png?nolink&400 |}} {{ :linux:linux_networking.png?nolink&400 |}}
  
-===== Statische IP - Beispiel Netzkonfiguration für Ubuntu =====+ 
 +===== Netzkonfiguration ab Ubuntu 18.04 / Debian X ===== 
 + 
 +**Ubuntu 17.10 and later** uses **Netplan** as the default network management tool. The previous Ubuntu versions were using ifconfig and its configuration file ''/etc/network/interfaces'' to configure the network. 
 +Netplan configuration files are written in YAML syntax with a ''.yaml'' file extension. To configure a network interface with Netplan, you need to create a YAML description for the interface, and Netplan will generate the required configuration files for the chosen renderer tool. 
 +Netplan supports two renderers, NetworkManager and Systemd-networkd. NetworkManager is mostly used on Desktop machines, while the Systemd-networkd is used on servers without a GUI. 
 + 
 +<WRAP center box 100%> 
 +==== Configuring Static IP address  ==== 
 + 
 +On Ubuntu 20.04, the system identifies network interfaces using ‘predictable network interface names’. 
 + 
 +The first step toward setting up a static IP address is identifying the name of the ethernet interface you want to configure. To do so, use the ip link command, as shown below: 
 + 
 +<code> 
 +# ip link 
 +</code> 
 + 
 +The command prints a list of all the available network interfaces. In this example, the name of the interface is ''ens3'': 
 + 
 +<sxh plain; gutter: false;> 
 +1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000 
 +    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 
 +2: ens3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP mode DEFAULT group default qlen 1000 
 +    link/ether 08:00:27:6c:13:63 brd ff:ff:ff:ff:ff:ff 
 +</sxh> 
 + 
 +Netplan configuration files are stored in the ''/etc/netplan'' directory. You’ll probably find one or more YAML files in this directory. The name of the file may differ from setup to setup. Usually, the file is named either ''01-netcfg.yaml'', ''50-cloud-init.yaml'', or ''NN_interfaceName.yaml'', but in your system it may be different. 
 + 
 +---- 
 + 
 +If your Ubuntu cloud instance is provisioned with cloud-init, you’ll need to disable it. To do so create the following file: 
 + 
 +<code> 
 +# vim /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg 
 +</code> 
 + 
 +<sxh bash; first-line: 1> 
 +network: {config: disabled} 
 +</sxh> 
 + 
 +---- 
 + 
 +To assign a static IP address on the network interface, open the YAML configuration file with your text editor : 
 + 
 +<code> 
 +# vim /etc/netplan/01-netcfg.yaml 
 +</code> 
 + 
 +<sxh bash; first-line: 1> 
 +network: 
 +  version: 2 
 +  renderer: networkd 
 +  ethernets: 
 +    ens3: 
 +      dhcp4: yes 
 +</sxh> 
 + 
 +Before changing the configuration, let’s explain the code in a short. 
 + 
 +Each Netplan Yaml file starts with the network key that has at least two required elements. The first required element is the version of the network configuration format, and the second one is the device type. The device type can be ethernets, bonds, bridges, or vlans. 
 + 
 +The configuration above also has a line that shows the renderer type. Out of the box, if you installed Ubuntu in server mode, the renderer is configured to use networkd as the back end. 
 +Under the device’s type (''ethernets''), you can specify one or more network interfaces. In this example, we have only one interface ens3 that is configured to obtain IP addressing from a DHCP server ''dhcp4: yes''
 + 
 +To assign a static IP address to ''ens3'' interface, edit the file as follows: 
 + 
 +  * Set DHCP to ''dhcp4: no''
 +  * Specify the static IP address. Under ''addresses:'' you can add one or more IPv4 or IPv6 IP addresses that will be assigned to the network interface. 
 +  * Specify the gateway. 
 +  * Under ''nameservers'', set the IP addresses of the nameservers. 
 + 
 +<sxh bash; first-line: 1> 
 +network: 
 +  version: 2 
 +  renderer: networkd 
 +  ethernets: 
 +    ens3: 
 +      dhcp4: no 
 +      addresses: 
 +        - 192.168.121.221/24 
 +      gateway4: 192.168.121.1 
 +      nameservers: 
 +          addresses: [8.8.8.8, 1.1.1.1] 
 +</sxh> 
 + 
 +When editing Yaml files, make sure you follow the YAML code indent standards. If the syntax is not correct, the changes will not be applied. 
 + 
 +---- 
 + 
 +Once done, save the file and apply the changes by running the following command: 
 + 
 +<code> 
 +# netplan apply 
 +</code> 
 + 
 +---- 
 + 
 +Verify the changes by typing: 
 + 
 +<code> 
 +# ip addr show dev ens3 
 +</code> 
 + 
 +<sxh plain; gutter: false;> 
 +2: ens3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000 
 +    link/ether 08:00:27:6c:13:63 brd ff:ff:ff:ff:ff:ff 
 +    inet 192.168.121.221/24 brd 192.168.121.255 scope global dynamic ens3 
 +       valid_lft 3575sec preferred_lft 3575sec 
 +    inet6 fe80::5054:ff:feb0:f500/64 scope link  
 +       valid_lft forever preferred_lft forever 
 +</sxh> 
 + 
 +<wrap em>That’s it! You have assigned a static IP to your Ubuntu server.</wrap> 
 + 
 +</WRAP> 
 + 
 + 
 + 
 + 
 + 
 + 
 + 
 + 
 +===== Statische IP - Beispiel Netzkonfiguration bis Ubuntu 16.04 / Debian X =====
  
 Dies ist eine Beispielkonfiguration, in der zwei Interfaces **eth0** und **eth1** <wrap em>mit statischer IP</wrap> und Angaben definiert wurden. Man kann nach diesem Beispiel noch beliebig weitere Interfaces erstellen. Dies ist eine Beispielkonfiguration, in der zwei Interfaces **eth0** und **eth1** <wrap em>mit statischer IP</wrap> und Angaben definiert wurden. Man kann nach diesem Beispiel noch beliebig weitere Interfaces erstellen.
Line 37: Line 161:
 broadcast 10.0.0.255 broadcast 10.0.0.255
 </sxh> </sxh>
 +
 +  * **auto ethX** sorgt dafür, dass das NIC bei jedem Neustart mit gestartet wird
 +  * **iface ethX inet static** definiert für das NIC eine statische IP
 +    * **address abc.def.ghi.jkl** spezifiziert die IP
 +    * **netmask** die Netzmaske
 +    * **gateway** das Standardgateway
 +    * **dns-nameservers** spezifiziert die DNS-Server. Es können beliebig viele eingetragen werden, diese werden dann der Reihe nach angefragt
 </WRAP> </WRAP>
  
Line 44: Line 175:
 <wrap em>Zum übernehmen der Interface Änderungen unten schauen!</wrap> <wrap em>Zum übernehmen der Interface Änderungen unten schauen!</wrap>
  
----- 
  
 ===== Dynamische IP - Beispiel Netzkonfiguration für Ubuntu ===== ===== Dynamische IP - Beispiel Netzkonfiguration für Ubuntu =====
Line 74: Line 204:
  
 </sxh> </sxh>
 +
 +  * Nutzt man **iface ethX inet dhcp** versucht sich das NIC die Konfiguration über DHCP zu holen, dann darf aber nach dieser Zeile keine weiter Konfiguration für dieses NIC vorgenommen werden.
 </WRAP> </WRAP>
  
 <wrap em>Zum übernehmen der Interface Änderungen unten schauen!</wrap> <wrap em>Zum übernehmen der Interface Änderungen unten schauen!</wrap>
  
----- 
  
 ===== Übernehmen der neuen Netzwerk Konfiguration ===== ===== Übernehmen der neuen Netzwerk Konfiguration =====
Line 86: Line 217:
 # ifup eth0</code> # ifup eth0</code>
   * ''Neustarten des Systems:'' <code># systemctl reboot</code>   * ''Neustarten des Systems:'' <code># systemctl reboot</code>
 +
 +
 +===== Weiteres bezüglich Netzwerk Konfiguration =====
 +
 +<WRAP center box 100%>
 +==== DNS-Config ====
 +Neben der Konfiguration der DNS-Server in der Datei **/etc/network/interfaces** kann dies auch über die Datei **etc/resolv.conf** geschehen.
 +Hier trägt man einen DNS-Server mit 
 +  nameserver ip.adresse.des.servers 
 +ein.
 +Hier ist Linux leider etwas inkonsequent! Gibt man DNS-Server in der **/etc/network/interfaces** an so muss man als key ''dns-nameservers'' nutzen, in der **/etc/resolv.conf** nutzt man ''nameserver''
 +</WRAP>
 +
 +----
 +
 +<WRAP center box 100%>
 +==== IP Forwarding ====
 +IP-Forwarding ist zuständig, dass IP-Pakete auf allen Netzwerkkarten weitergeleitet werden.
 +Das benötigt man zum Beispiel bei einem gehosteten Subnetz bei einem ISP. Da dies ein Kernelmodul ist, muss es in ''/etc/sysctl.conf'' dauerhaft aktiviert werden. Hierzu muss die Zeile mit IP-Forward wie folgt angepasst werden:
 +  net.ipv4.ip_forward=1
 +
 +Möchte man dieses Modul nur temporär aktivieren macht man dies über das Terminal:  
 +  # sysctl net.ipv4.ip_forward=1
 +</WRAP>
 +
 +----
 +
 +<WRAP center box 100%>
 +==== Statische Routen ====
 +Nutzt man mehrere Netzwerke ergibt sich manchmal das Problem, dass der Server die Route in ein bestimmten Netz nicht findet, da zum Beispiel der "Zugang" zu diesem Netz auf einem Server liegt, der kein Gateway ist (Beispielsweise bei OpenVPN).
 +Um trotzdem auf diese Netze zu kommen kann man statische Routen festlegen:
 +Dies geht temporär mit 
 +  sudo route add -net 10.8.0.0 netmask 255.255.255.0 gw vpn.server.i.p 
 +Hierbei ist das LAN **10.8.0.0/24** das Netzwerk in das geroutet werden soll und **vpn.server.i.p** der Server, der den "physikalischen" Zugang zum Netz darstellt.
 +Damit diese Routen persistent bleiben müssen sie in ohne ''sudo'' in die Datei **/etc/rc.local** eingetragen werden:
 +  route add -net 10.8.0.0 netmask 255.255.255.0 gw vpn.server.i.p
 +</WRAP>
 + 
 +  
 +
  
  • debian/base-debian/networking-debian.1556892332.txt.gz
  • Last modified: 2019/05/03 16:05
  • by michael