{"id":8692,"date":"2021-07-30T08:58:22","date_gmt":"2021-07-30T08:58:22","guid":{"rendered":"https:\/\/linuxways.net\/?p=8692"},"modified":"2021-07-30T08:58:22","modified_gmt":"2021-07-30T08:58:22","slug":"linux-ip-command-with-examples","status":"publish","type":"post","link":"https:\/\/linuxways.net\/de\/centos\/linux-ip-command-with-examples\/","title":{"rendered":"Linux IP Command with Examples"},"content":{"rendered":"<p>The IP command is a networking command that provides information about network interfaces and also performs network configuration. For instance, you can manually assign an IP address, view all network interfaces, manage the routing table, enable or disable a network interface, and so on.<\/p>\n<p>In this tutorial, we examine various use cases of the Linux IP command using some practical examples.<\/p>\n<h2><strong>Basic Syntax<\/strong><\/h2>\n<p>The IP command takes the following syntax:<\/p>\n<pre><strong>$ ip [ OPTIONS ] OBJECT { COMMAND | help }<\/strong><\/pre>\n<h2><strong>Display information about network interfaces<\/strong><\/h2>\n<p>One of the common uses of the IP command is to display the system\u2019s network interface. You can use the command below to display information about all the system\u2019s network interfaces including the IP address, mac address, link status ( whether up or down ), and MTU ( Maximum Transmission Unit )<\/p>\n<pre><strong>$ ip addr<\/strong><\/pre>\n<p>OR<\/p>\n<pre><strong>$ ip a<\/strong><\/pre>\n<p>As mentioned, the commands provide detailed information about the attached network interface as indicated,<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"927\" height=\"322\" class=\"wp-image-8693\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/07\/word-image-675.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/07\/word-image-675.png 927w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/07\/word-image-675-300x104.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/07\/word-image-675-768x267.png 768w\" sizes=\"auto, (max-width: 927px) 100vw, 927px\" \/><\/p>\n<h2><strong>Display IPv4 and IPv6 addresses only<\/strong><\/h2>\n<p>You can choose to list either IPv4 or IPv6 addresses as shown. To display all the IPv4 addresses of network interfaces, run the command:<\/p>\n<pre><strong>$ ip -4 a<\/strong><\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"879\" height=\"287\" class=\"wp-image-8694\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/07\/word-image-676.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/07\/word-image-676.png 879w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/07\/word-image-676-300x98.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/07\/word-image-676-768x251.png 768w\" sizes=\"auto, (max-width: 879px) 100vw, 879px\" \/><\/p>\n<p>To list IPv6 addresses of all the interfaces, execute:<\/p>\n<pre><strong>$ ip -6 a<\/strong><\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"879\" height=\"286\" class=\"wp-image-8695\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/07\/word-image-677.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/07\/word-image-677.png 879w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/07\/word-image-677-300x98.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/07\/word-image-677-768x250.png 768w\" sizes=\"auto, (max-width: 879px) 100vw, 879px\" \/><\/p>\n<h2><strong>Display information about a specific network interface<\/strong><\/h2>\n<p>So far, we have displayed information about all the network interfaces. But what if you are not interested in getting information about one interface. How do you go about doing it?<\/p>\n<p>To display information about an interface, use the syntax:<\/p>\n<pre><strong>$ ip a show dev interface_name<\/strong><\/pre>\n<p>For instance, to gather information on the <strong>enp0s3 <\/strong>interface only, run the command:<\/p>\n<pre><strong>$ ip a show dev enp0s3<\/strong><\/pre>\n<p>OR<\/p>\n<pre><strong>$ ip a list enp0s3<\/strong><\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"880\" height=\"463\" class=\"wp-image-8696\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/07\/word-image-678.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/07\/word-image-678.png 880w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/07\/word-image-678-300x158.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/07\/word-image-678-768x404.png 768w\" sizes=\"auto, (max-width: 880px) 100vw, 880px\" \/><\/p>\n<h2><strong>Assign an IP address to an interface<\/strong><\/h2>\n<p>Let\u2019s now focus on how you can assign an IP address to an interface. To do so, use the command syntax:<\/p>\n<pre><strong>$ ip a add {ip_addr\/mask} dev {interface}<\/strong><\/pre>\n<p>For example, to assign the <strong>enp0s3 <\/strong>interface an IP of <strong>192.168.2.120 <\/strong>with <strong>255.255.255.0 <\/strong>subnet mask, run the command.<\/p>\n<pre><strong>$ sudo ip a add 192.168.2.120\/255.255.255.0 dev enp0s3<\/strong><\/pre>\n<p>Or you can use the <strong>\/24 <\/strong>CIDR notation for the subnet mask as follows<\/p>\n<pre><strong>$ sudo ip a add 192.168.2.120\/24 dev enp0s3<\/strong><\/pre>\n<p><strong><img loading=\"lazy\" decoding=\"async\" width=\"879\" height=\"377\" class=\"wp-image-8697\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/07\/word-image-679.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/07\/word-image-679.png 879w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/07\/word-image-679-300x129.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/07\/word-image-679-768x329.png 768w\" sizes=\"auto, (max-width: 879px) 100vw, 879px\" \/><\/strong><\/p>\n<h2><strong>Delete an IP address from a network interface<\/strong><\/h2>\n<p>To delete the IP address assigned to the interface, run the command:<\/p>\n<pre><strong>$ sudo ip a del 192.168.2.120\/255.255.255.0 dev enp0s3<\/strong><\/pre>\n<p>You can then verify the changes as follows:<\/p>\n<pre><strong>$ ip a show dev enp0s3<\/strong><\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"880\" height=\"365\" class=\"wp-image-8698\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/07\/word-image-680.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/07\/word-image-680.png 880w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/07\/word-image-680-300x124.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/07\/word-image-680-768x319.png 768w\" sizes=\"auto, (max-width: 880px) 100vw, 880px\" \/><\/p>\n<h2><strong>Bring an interface UP or DOWN<\/strong><\/h2>\n<p>To modify the state of a network interface, by enabling or disabling it, run the command syntax<\/p>\n<pre><strong>$ sudo ip link set dev DEVICE_NAME {up|down}<\/strong><\/pre>\n<p>To bring down the <strong>enp0s3 <\/strong>interface, run:<\/p>\n<pre><strong>$ sudo ip link set dev enp0s3 down<\/strong><\/pre>\n<p>To bring it up, execute:<\/p>\n<pre><strong>$ sudo ip link set dev enp0s3 up<\/strong><\/pre>\n<p><strong><img loading=\"lazy\" decoding=\"async\" width=\"879\" height=\"214\" class=\"wp-image-8699\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/07\/word-image-681.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/07\/word-image-681.png 879w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/07\/word-image-681-300x73.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/07\/word-image-681-768x187.png 768w\" sizes=\"auto, (max-width: 879px) 100vw, 879px\" \/><\/strong><\/p>\n<h2><strong>Display Routing table<\/strong><\/h2>\n<p>To display the routing table of your Linux system, run the command<\/p>\n<pre><strong>$ ip r<\/strong><\/pre>\n<p><strong><img loading=\"lazy\" decoding=\"async\" width=\"880\" height=\"219\" class=\"wp-image-8700\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/07\/word-image-682.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/07\/word-image-682.png 880w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/07\/word-image-682-300x75.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/07\/word-image-682-768x191.png 768w\" sizes=\"auto, (max-width: 880px) 100vw, 880px\" \/><\/strong><\/p>\n<h2><strong>Conclusion<\/strong><\/h2>\n<p>That was a summary of the practical use cases of the Linux IP command. Those are some of the widely used command examples that Linux users run from time to time.<\/p>","protected":false},"excerpt":{"rendered":"<p>The IP command is a networking command that provides information about network interfaces and also performs network configuration. For instance, you can manually assign an IP address, view&hellip;<\/p>","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1,4,5,83,165,2],"tags":[447],"class_list":["post-8692","post","type-post","status-publish","format-standard","hentry","category-centos","category-debian","category-mint","category-opensuse","category-red-hat","category-ubuntu","tag-ip-command"],"_links":{"self":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts\/8692","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/comments?post=8692"}],"version-history":[{"count":0,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts\/8692\/revisions"}],"wp:attachment":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/media?parent=8692"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/categories?post=8692"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/tags?post=8692"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}