Ip/Befehl: Unterschied zwischen den Versionen
Keine Bearbeitungszusammenfassung |
|||
Zeile 1: | Zeile 1: | ||
==Befehle und Dateien zum Routing== | Das Kommando '''ip''' aus der iproute2 Toolsammlung dient unter [[Linux]] zur '''Konfiguration von Netzwerkadressen'''. Es '''ersetzt das ifconfig Kommando''' aus den obsoleten net-tools. Dieser Artikel zeigt die wichtigsten Parameter des ip Kommandos anhand einiger Beispiele. | ||
== Vergleichstabelle ip versus ifconfig == | |||
Die Tabelle zeigt wichtige Befehle zur Netzwerkkonfiguration und vergleicht die Syntax der Kommandos ip und ifconfig: | |||
{| class="wikitable" | |||
|- style="background-color: #EFEFEF; font-weight: bold;"==Befehle und Dateien zum Routing== | |||
===Linux/Debian=== | ===Linux/Debian=== | ||
Zeile 20: | Zeile 25: | ||
*route add – fügt eine neue Route hinzu | *route add – fügt eine neue Route hinzu | ||
*route del – löscht eine Route | *route del – löscht eine Route | ||
! Zweck | |||
! iproute2 Kommando | |||
! iproute2 Kommando Kurzversion | |||
! net-tools Kommando | |||
|- | |||
| Linkstatus anzeigen | |||
| [[#ip link show|<code>ip link show</code>]] | |||
| <code>ip l</code> | |||
| <code>ifconfig</code> | |||
|- | |||
| Linkstatus inkl. Statistik <br>(RX/TX bytes, errors, ...) anzeigen | |||
| [[#ip link show|<code>ip -statistics link show</code>]] | |||
| <code>ip -s l</code> | |||
| <code>ifconfig</code> | |||
|- | |||
| IP Adresse anzeigen | |||
| [[#ip addr show|<code>ip addr show</code>]] | |||
| <code>ip a</code> | |||
| <code>ifconfig -a</code> | |||
|- | |||
| IP Adresse setzen | |||
| [[#ip addr add IP/NETMASK dev DEVICE|<code>ip addr add IP/NETMASK dev DEVICE</code>]] | |||
| <code>ip a a IP/NETMASK dev DEVICE</code> | |||
| <code>ifconfig DEVICE IP/NETMASK</code> | |||
|- | |||
| IP Adresse entfernen | |||
| [[#ip addr add IP/NETMASK dev DEVICE|<code>ip addr del IP/NETMASK dev DEVICE</code>]] | |||
| <code>ip a d IP/NETMASK dev DEVICE</code> | |||
| | |||
|- | |||
| IP Adressen entfernen | |||
| [[#ip addr flush dev DEVICE|<code>ip addr flush dev DEVICE</code>]] | |||
| <code>ip a f dev DEVICE</code> | |||
| | |||
|- | |||
| Routingtabelle anzeigen | |||
| [[#ip route show|<code>ip route show</code>]] | |||
| <code>ip r</code> | |||
| <code>route -n</code> | |||
|- | |||
| Standardgateway setzen | |||
| [[#ip route add default via IP|<code>ip route add default via IP</code>]] | |||
| <code>ip r a default via IP</code> | |||
| <code>route add default gw IP DEVICE</code> | |||
|- | |||
| ARP-Cache anzeigen | |||
| [[#ip neigh show|<code>ip neigh show</code>]] | |||
| <code>ip n</code> | |||
| <code>arp -na</code> | |||
|- | |||
| Verbindungen anzeigen | |||
| <code>ss --tcp --all --processes --extended --numeric</code> | |||
| <code>ss -tapen</code> | |||
| <code>netstat -tapen</code> | |||
|} | |||
== Beispiele == | |||
Die folgenden Ausgaben zeigen einige Beispiele von iproute2 Kommandos. | |||
=== ip help === | |||
<pre> | |||
$ ip help | |||
Usage: ip [ OPTIONS ] OBJECT { COMMAND | help } | |||
ip [ -force ] -batch filename | |||
where OBJECT := { link | addr | addrlabel | route | rule | neigh | ntable | | |||
tunnel | tuntap | maddr | mroute | mrule | monitor | xfrm | | |||
netns } | |||
OPTIONS := { -V[ersion] | -s[tatistics] | -d[etails] | -r[esolve] | | |||
-f[amily] { inet | inet6 | ipx | dnet | link } | | |||
-l[oops] { maximum-addr-flush-attempts } | | |||
-o[neline] | -t[imestamp] | -b[atch] [filename] | | |||
-rc[vbuf] [size]} | |||
</pre> | |||
=== ip link show === | |||
<pre> | |||
$ ip link show | |||
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN | |||
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 | |||
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000 | |||
link/ether 08:00:27:66:72:e1 brd ff:ff:ff:ff:ff:ff | |||
</pre> | |||
=== ip -statistics link show === | |||
<pre> | |||
$ ip link show | |||
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN | |||
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 | |||
RX: bytes packets errors dropped overrun mcast | |||
2073916 4895 0 0 0 0 | |||
TX: bytes packets errors dropped carrier collsns | |||
2073916 4895 0 0 0 0 | |||
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000 | |||
link/ether 08:00:27:66:72:e1 brd ff:ff:ff:ff:ff:ff | |||
RX: bytes packets errors dropped overrun mcast | |||
1716782262 1369751 0 0 0 0 | |||
TX: bytes packets errors dropped carrier collsns | |||
308636400 1172428 0 0 0 0 | |||
</pre> | |||
=== ip addr show === | |||
<pre> | |||
$ ip addr show | |||
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN | |||
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 | |||
inet 127.0.0.1/8 scope host lo | |||
valid_lft forever preferred_lft forever | |||
inet6 ::1/128 scope host | |||
valid_lft forever preferred_lft forever | |||
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000 | |||
link/ether 08:00:27:66:72:e1 brd ff:ff:ff:ff:ff:ff | |||
inet 10.1.102.59/24 brd 10.1.102.255 scope global eth0 | |||
valid_lft forever preferred_lft forever | |||
inet6 fe80::a00:27ff:fe66:72e1/64 scope link | |||
valid_lft forever preferred_lft forever | |||
</pre> | |||
=== ip addr add IP/NETMASK dev DEVICE === | |||
<pre> | |||
$ sudo ip addr add 10.1.102.60/24 dev eth0 | |||
$ ip a | |||
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN | |||
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 | |||
inet 127.0.0.1/8 scope host lo | |||
valid_lft forever preferred_lft forever | |||
inet6 ::1/128 scope host | |||
valid_lft forever preferred_lft forever | |||
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000 | |||
link/ether 08:00:27:66:72:e1 brd ff:ff:ff:ff:ff:ff | |||
inet 10.1.102.59/24 brd 10.1.102.255 scope global eth0 | |||
valid_lft forever preferred_lft forever | |||
inet 10.1.102.60/24 scope global secondary eth0 | |||
valid_lft forever preferred_lft forever | |||
inet6 fe80::a00:27ff:fe66:72e1/64 scope link | |||
valid_lft forever preferred_lft forever | |||
</pre> | |||
=== ip addr del IP/NETMASK dev DEVICE === | |||
<pre> | |||
$ sudo ip addr del 10.1.102.60/24 dev eth0 | |||
$ ip a | |||
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN | |||
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 | |||
inet 127.0.0.1/8 scope host lo | |||
valid_lft forever preferred_lft forever | |||
inet6 ::1/128 scope host | |||
valid_lft forever preferred_lft forever | |||
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000 | |||
link/ether 08:00:27:15:17:5e brd ff:ff:ff:ff:ff:ff | |||
inet 10.1.102.54/24 brd 10.1.102.255 scope global eth0 | |||
valid_lft forever preferred_lft forever | |||
inet6 fe80::a00:27ff:fe15:175e/64 scope link | |||
valid_lft forever preferred_lft forever | |||
</pre> | |||
=== ip addr flush dev DEVICE === | |||
<pre> | |||
$ sudo ip addr flush dev eth0 | |||
$ ip a | |||
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN | |||
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 | |||
inet 127.0.0.1/8 scope host lo | |||
valid_lft forever preferred_lft forever | |||
inet6 ::1/128 scope host | |||
valid_lft forever preferred_lft forever | |||
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000 | |||
link/ether 08:00:27:15:17:5e brd ff:ff:ff:ff:ff:ff | |||
</pre> | |||
=== ip route show === | |||
<pre> | |||
$ ip route show | |||
default via 10.1.102.1 dev eth0 metric 100 | |||
10.1.102.0/24 dev eth0 proto kernel scope link src 10.1.102.59 | |||
</pre> | |||
=== ip route add default via IP === | |||
<pre> | |||
$ sudo ip route add d via 10.1.102.1 | |||
</pre> | |||
=== ip neigh show === | |||
<pre> | |||
$ ip neigh show | |||
10.1.102.101 dev eth0 lladdr f0:de:f1:f3:17:88 REACHABLE | |||
10.1.102.1 dev eth0 lladdr 00:0c:42:97:79:63 REACHABLE | |||
</pre> |
Version vom 23. August 2019, 10:58 Uhr
Das Kommando ip aus der iproute2 Toolsammlung dient unter Linux zur Konfiguration von Netzwerkadressen. Es ersetzt das ifconfig Kommando aus den obsoleten net-tools. Dieser Artikel zeigt die wichtigsten Parameter des ip Kommandos anhand einiger Beispiele.
Vergleichstabelle ip versus ifconfig
Die Tabelle zeigt wichtige Befehle zur Netzwerkkonfiguration und vergleicht die Syntax der Kommandos ip und ifconfig:
Linux/Debian
- ip a – zeigt alle Netzwerkkarten; zeigt auch,ob die Karten an oder aus sind
- ip r – zeigt Routingtabelle.
- ip link set up/down – fährt eine Netzwerkkarte hoch/runter
- ping <IP-Addresse> - schickt ein ICMP-Signal an den Zielrechner; zum Überprüfen, ob man mit dem Netz verbunden ist.
- /etc/network/interfaces.d/ - Verzeichnis mit allen konfigurierten Netzwerkschnittstellen, wenn man nicht den NetworkManager benutzen möchte
(In unserem Fall haben wir vier Dateien: enp1s6.conf, enp1s8.conf, enp1s.conf, enp0s6) In der Datei enp1s6.conf steht folgendes:
allow-hotplug enp1s6 iface enp1s6 inet static address 10.30.0.1 netmask 255.255.0.0
freeBSD
- netstat -r – zeigt Routingtabelle
- route add – fügt eine neue Route hinzu
- route del – löscht eine Route
Zweck | iproute2 Kommando | iproute2 Kommando Kurzversion | net-tools Kommando |
---|---|---|---|
Linkstatus anzeigen | ip link show
|
ip l
|
ifconfig
|
Linkstatus inkl. Statistik (RX/TX bytes, errors, ...) anzeigen |
ip -statistics link show
|
ip -s l
|
ifconfig
|
IP Adresse anzeigen | ip addr show
|
ip a
|
ifconfig -a
|
IP Adresse setzen | ip addr add IP/NETMASK dev DEVICE
|
ip a a IP/NETMASK dev DEVICE
|
ifconfig DEVICE IP/NETMASK
|
IP Adresse entfernen | ip addr del IP/NETMASK dev DEVICE
|
ip a d IP/NETMASK dev DEVICE
|
|
IP Adressen entfernen | ip addr flush dev DEVICE
|
ip a f dev DEVICE
|
|
Routingtabelle anzeigen | ip route show
|
ip r
|
route -n
|
Standardgateway setzen | ip route add default via IP
|
ip r a default via IP
|
route add default gw IP DEVICE
|
ARP-Cache anzeigen | ip neigh show
|
ip n
|
arp -na
|
Verbindungen anzeigen | ss --tcp --all --processes --extended --numeric
|
ss -tapen
|
netstat -tapen
|
Beispiele
Die folgenden Ausgaben zeigen einige Beispiele von iproute2 Kommandos.
ip help
$ ip help Usage: ip [ OPTIONS ] OBJECT { COMMAND | help } ip [ -force ] -batch filename where OBJECT := { link | addr | addrlabel | route | rule | neigh | ntable | tunnel | tuntap | maddr | mroute | mrule | monitor | xfrm | netns } OPTIONS := { -V[ersion] | -s[tatistics] | -d[etails] | -r[esolve] | -f[amily] { inet | inet6 | ipx | dnet | link } | -l[oops] { maximum-addr-flush-attempts } | -o[neline] | -t[imestamp] | -b[atch] [filename] | -rc[vbuf] [size]}
ip link show
$ ip link show 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000 link/ether 08:00:27:66:72:e1 brd ff:ff:ff:ff:ff:ff
ip -statistics link show
$ ip link show 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 RX: bytes packets errors dropped overrun mcast 2073916 4895 0 0 0 0 TX: bytes packets errors dropped carrier collsns 2073916 4895 0 0 0 0 2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000 link/ether 08:00:27:66:72:e1 brd ff:ff:ff:ff:ff:ff RX: bytes packets errors dropped overrun mcast 1716782262 1369751 0 0 0 0 TX: bytes packets errors dropped carrier collsns 308636400 1172428 0 0 0 0
ip addr show
$ ip addr show 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo valid_lft forever preferred_lft forever inet6 ::1/128 scope host valid_lft forever preferred_lft forever 2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000 link/ether 08:00:27:66:72:e1 brd ff:ff:ff:ff:ff:ff inet 10.1.102.59/24 brd 10.1.102.255 scope global eth0 valid_lft forever preferred_lft forever inet6 fe80::a00:27ff:fe66:72e1/64 scope link valid_lft forever preferred_lft forever
ip addr add IP/NETMASK dev DEVICE
$ sudo ip addr add 10.1.102.60/24 dev eth0 $ ip a 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo valid_lft forever preferred_lft forever inet6 ::1/128 scope host valid_lft forever preferred_lft forever 2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000 link/ether 08:00:27:66:72:e1 brd ff:ff:ff:ff:ff:ff inet 10.1.102.59/24 brd 10.1.102.255 scope global eth0 valid_lft forever preferred_lft forever inet 10.1.102.60/24 scope global secondary eth0 valid_lft forever preferred_lft forever inet6 fe80::a00:27ff:fe66:72e1/64 scope link valid_lft forever preferred_lft forever
ip addr del IP/NETMASK dev DEVICE
$ sudo ip addr del 10.1.102.60/24 dev eth0 $ ip a 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo valid_lft forever preferred_lft forever inet6 ::1/128 scope host valid_lft forever preferred_lft forever 2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000 link/ether 08:00:27:15:17:5e brd ff:ff:ff:ff:ff:ff inet 10.1.102.54/24 brd 10.1.102.255 scope global eth0 valid_lft forever preferred_lft forever inet6 fe80::a00:27ff:fe15:175e/64 scope link valid_lft forever preferred_lft forever
ip addr flush dev DEVICE
$ sudo ip addr flush dev eth0 $ ip a 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo valid_lft forever preferred_lft forever inet6 ::1/128 scope host valid_lft forever preferred_lft forever 2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000 link/ether 08:00:27:15:17:5e brd ff:ff:ff:ff:ff:ff
ip route show
$ ip route show default via 10.1.102.1 dev eth0 metric 100 10.1.102.0/24 dev eth0 proto kernel scope link src 10.1.102.59
ip route add default via IP
$ sudo ip route add d via 10.1.102.1
ip neigh show
$ ip neigh show 10.1.102.101 dev eth0 lladdr f0:de:f1:f3:17:88 REACHABLE 10.1.102.1 dev eth0 lladdr 00:0c:42:97:79:63 REACHABLE