{"id":7108,"date":"2020-06-14T22:09:27","date_gmt":"2020-06-14T20:09:27","guid":{"rendered":"https:\/\/michlstechblog.info\/blog\/?p=7108"},"modified":"2020-06-16T15:18:38","modified_gmt":"2020-06-16T13:18:38","slug":"linux-ip-command-line-examples","status":"publish","type":"post","link":"https:\/\/michlstechblog.info\/blog\/linux-ip-command-line-examples\/","title":{"rendered":"Linux: ip command line examples"},"content":{"rendered":"<div class=\"twoclick_social_bookmarks_post_7108 social_share_privacy clearfix 1.6.4 locale-en_US sprite-en_US\"><\/div><div class=\"twoclick-js\"><script type=\"text\/javascript\">\/* <![CDATA[ *\/\njQuery(document).ready(function($){if($('.twoclick_social_bookmarks_post_7108')){$('.twoclick_social_bookmarks_post_7108').socialSharePrivacy({\"services\":{\"flattr\":{\"uid\":\"Michl\",\"status\":\"on\",\"the_title\":\"Linux%3A%20ip%20command%20line%20examples\",\"the_excerpt\":\"Hi%2C%0D%0A%0D%0Athe%20old%20style%20ifconfig%2C%20route%20and%20netstat%20commands%20does%20not%20support%20all%20network%2C%20especially%20IPv6%2C%20%20features%20shipped%20with%20modern%20linux%20distributions.%20%0D%0A%0D%0AReplacement%20are%20ip%20%28ifconfig%2C%20route%29%20and%20ss%20%28netstat%29.%20Here%20are%20some%20examples.%0D%0A%20%28more%26hellip%3B%29\",\"txt_info\":\"2 clicks for more data protection:\\r\\n\\r\\nOnly when you click here, the button will be come active and you can send your recommendation to Flattr. When activating, data are transmitted to third parties. \",\"perma_option\":\"off\"}},\"txt_help\":\"When you activate these fields by clicking, information to Flattr may be transferred abroad, and probably may also stored there.\",\"settings_perma\":\"Enable permanently and accept data transmission. \",\"info_link\":\"http:\\\/\\\/www.heise.de\\\/ct\\\/artikel\\\/2-Klicks-fuer-mehr-Datenschutz-1333879.html\",\"uri\":\"https:\\\/\\\/michlstechblog.info\\\/blog\\\/linux-ip-command-line-examples\\\/\",\"post_id\":7108,\"post_title_referrer_track\":\"Linux%3A+ip+command+line+examples\",\"display_infobox\":\"on\"});}});\n\/* ]]> *\/<\/script><\/div><p>Hi,<\/p>\n<p>the old style ifconfig, route and netstat commands does not support all network, especially IPv6,  features shipped with modern linux distributions. <\/p>\n<p>Replacement are ip (ifconfig, route) and ss (netstat). Here are some examples.<br \/>\n<!--more--><br \/>\nShow all interface addresses<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nroot@devdeb ~ # ip address show\r\n<\/pre>\n<p>To show an compact view, less verbose output use the -brief or -br switch <\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nroot@devdeb ~ # ip -br address show\r\n<\/pre>\n<p>Or for a better overview use a colored output<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nroot@devdeb ~ # ip -color -br address show\r\n<\/pre>\n<p>Te output can formatted as JSON for further processings <\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nroot@devdeb ~ # ip -j address show\r\n<\/pre>\n<p>Show IPv4 interface addresses. -4 is a shortcut for -family inet<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nroot@devdeb ~ # ip -4 address show\r\n<\/pre>\n<p>Show IPv6 interface addresses. -6 is a shortcut for -family inet6<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nroot@devdeb ~ # ip -6 address show\r\n<\/pre>\n<p>Show MAC Addresses. -0 is a shortcut for -family link<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nroot@devdeb ~ # ip -0 address show\r\n<\/pre>\n<p>Show statistic (Send\/received bytes, errors, etc)  of the interfaces<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nroot@devdeb ~ # ip -stats link show\r\n<\/pre>\n<p>Parameters can be shortened if the shortcut is unique. For example address and show<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nroot@devdeb ~ # ip -0 a s\r\n<\/pre>\n<p>Show addresses of an specific interface<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nroot@devdeb ~ # ip address show dev enp0s25\r\n<\/pre>\n<p>And without link local addresses<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nroot@devdeb ~ # ip address show dev enp0s25 scope global\r\n<\/pre>\n<p>Set an IP (v4) Address<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nroot@devdeb ~ # ip addr add 10.254.10.10\/24 dev enp0s25\r\n<\/pre>\n<p>ifup<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nroot@devdeb ~ # ip link set enp0s25 up\r\n<\/pre>\n<p>ifdown<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nroot@devdeb ~ # ip link set enp0s25 down\r\n<\/pre>\n<p>Delete an IP (v4) Address<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nroot@devdeb ~ # ip addr del 10.254.10.10\/24 dev enp0s25\r\n<\/pre>\n<p>Show the IPv4 arp cache<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nroot@devdeb ~ # ip neighbor show\r\n<\/pre>\n<p>Show the IPv6 neighbor cache<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nroot@devdeb ~ # ip -6 neighbor show\r\n<\/pre>\n<p>Show IPv4 routing table<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nroot@devdeb ~ # ip route show\r\n<\/pre>\n<p>Show IPv6 routing table<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nroot@devdeb ~ # ip -6 route show\r\n<\/pre>\n<p>Add a IPv4 route<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nroot@devdeb ~ # ip route add 10.253.1.0\/24 via 10.254.10.1 dev enp0s25\r\n<\/pre>\n<p>Delete a IPv4 route<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nroot@devdeb ~ # ip route del 10.253.1.0\/24\r\n<\/pre>\n<p>Add a default route\/default gateway<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nroot@devdeb ~ # ip route add default via 10.254.10.1\r\n<\/pre>\n<p>Show default route <\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nroot@devdeb ~ # ip route show match default\r\n<\/pre>\n<p>Add a additional routing table for policy based routing<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nroot@devdeb ~ # ip rule add fwmark 2 table 2\r\nroot@devdeb ~ # ip route add 10.11.1.0\/0 table 2 via 10.254.10.1 dev enp0s25\r\n<\/pre>\n<p>This table is used when iptables MARKs a connection with number of the fwmark property of the table  <\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nroot@devdeb ~ # iptables -A PREROUTING -t mangle -p tcp -s 10.254.1.25\/32  --dport 443 -j MARK --set-mark 2\r\n<\/pre>\n<p>Show all routing tables<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nroot@devdeb ~ # ip route show table all\r\n<\/pre>\n<p>And delete such a route<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nroot@devdeb ~ # ip route del 10.11.1.0\/0 table 2\r\n<\/pre>\n<p>To monitor change events on the network interfaces use<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nroot@devdeb ~ # ip monitor\r\n<\/pre>\n<p>With switches -ts and label a time stamp and the family of the message is shown as prefix<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nroot@devdeb ~ # ip -ts monitor label\r\n<\/pre>\n<p>The replacement for netstat is ss<br \/>\nThe following command shows all listing tcp and udp sockets and the program that listens to<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nroot@devdeb ~ # ss --tcp --udp --listening --processes --numeric\r\n<\/pre>\n<p>Display all TCP connections<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nroot@devdeb ~ # ss -t -a\r\n<\/pre>\n<p>Display UNIX domain sockets<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nroot@devdeb ~ # ss -x\r\n<\/pre>\n<p>Show multicast addresses\/group memberships<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nroot@devdeb ~ # ip maddress\r\n<\/pre>\n<p>Michael<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hi, the old style ifconfig, route and netstat commands does not support all network, especially IPv6, features shipped with modern linux distributions. Replacement are ip (ifconfig, route) and ss (netstat). Here are some examples.<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[1112,188,515,182,278,189,224,549,1454,551,571],"class_list":["post-7108","post","type-post","status-publish","format-standard","hentry","category-linux","tag-arp-cache","tag-command","tag-examples","tag-ip","tag-ip-address","tag-line","tag-linux-2","tag-mac-address","tag-policy-based-routing","tag-routing","tag-show"],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/michlstechblog.info\/blog\/wp-json\/wp\/v2\/posts\/7108","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/michlstechblog.info\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/michlstechblog.info\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/michlstechblog.info\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/michlstechblog.info\/blog\/wp-json\/wp\/v2\/comments?post=7108"}],"version-history":[{"count":25,"href":"https:\/\/michlstechblog.info\/blog\/wp-json\/wp\/v2\/posts\/7108\/revisions"}],"predecessor-version":[{"id":7137,"href":"https:\/\/michlstechblog.info\/blog\/wp-json\/wp\/v2\/posts\/7108\/revisions\/7137"}],"wp:attachment":[{"href":"https:\/\/michlstechblog.info\/blog\/wp-json\/wp\/v2\/media?parent=7108"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/michlstechblog.info\/blog\/wp-json\/wp\/v2\/categories?post=7108"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/michlstechblog.info\/blog\/wp-json\/wp\/v2\/tags?post=7108"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}