{"id":11310,"date":"2019-03-13T00:28:11","date_gmt":"2019-03-13T00:28:11","guid":{"rendered":"http:\/\/www.appservgrid.com\/paw92\/?p=11310"},"modified":"2019-03-13T00:28:11","modified_gmt":"2019-03-13T00:28:11","slug":"10-useful-ip-commands-to-configure-network-interfaces","status":"publish","type":"post","link":"https:\/\/www.appservgrid.com\/paw92\/index.php\/2019\/03\/13\/10-useful-ip-commands-to-configure-network-interfaces\/","title":{"rendered":"10 Useful \u201cIP\u201d Commands to Configure Network Interfaces"},"content":{"rendered":"<p>In this post, we are going to review how we can assign\u00a0<strong>Static IP Address<\/strong>,\u00a0<strong>Static Route<\/strong>,\u00a0<strong>Default Gateway<\/strong>\u00a0etc.\u00a0 Assigning IP Address on demand using\u00a0<b>IP<\/b>\u00a0command.\u00a0<a href=\"https:\/\/www.tecmint.com\/ifconfig-command-examples\/\" target=\"_blank\" rel=\"noopener\">IFCONFIG command<\/a>\u00a0is deprecated and replaced by\u00a0<b>IP<\/b>command in\u00a0<strong>Linux<\/strong>. However,\u00a0<b>IFCONFIG<\/b>\u00a0command is still works and available for most of the Linux distributions.<\/p>\n<p><b>Don\u2019t Miss:<\/b>\u00a0<a href=\"https:\/\/www.tecmint.com\/ifconfig-vs-ip-command-comparing-network-configuration\/\" target=\"_blank\" rel=\"noopener\">ifconfig vs ip: What\u2019s Difference and Comparing Commands<\/a><\/p>\n<div id=\"attachment_2349\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2013\/03\/IP-Command-Examples.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-medium wp-image-2349\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2013\/03\/IP-Command-Examples-300x215.png\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" srcset=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2013\/03\/IP-Command-Examples-300x215.png 300w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2013\/03\/IP-Command-Examples.png 442w\" alt=\"IP Command Examples\" width=\"300\" height=\"215\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p class=\"wp-caption-text\">10 IP Command Examples<\/p>\n<\/div>\n<p><strong>Note:<\/strong>\u00a0Please take configuration file backup before doing any changes.<\/p>\n<h3>How do i Configure Static IP Address Internet Protocol (IPv4)<\/h3>\n<p>To configure static IP Address, you need to update or edit network configuration file to assign an Static IP Address to a system. You must be superuser with\u00a0<b>su (switch user)<\/b>\u00a0command from terminal or command prompt.<\/p>\n<h4>For RHEL\/CentOS\/Fedora<\/h4>\n<p>Open and edit network configuration file for (<strong>eth0<\/strong>\u00a0or\u00a0<strong>eth1<\/strong>) using your favorite editor. For example, to assigning IP Address to\u00a0<strong>eth0<\/strong>\u00a0interface as follows.<\/p>\n<pre>[root@tecmint ~]# vi \/etc\/sysconfig\/network-scripts\/ifcfg-eth0<\/pre>\n<h5>Simple output:<\/h5>\n<pre>DEVICE=\"eth0\"\r\nBOOTPROTO=static\r\nONBOOT=yes\r\nTYPE=\"Ethernet\"\r\nIPADDR=192.168.50.2\r\nNAME=\"System eth0\"\r\nHWADDR=00:0C:29:28:FD:4C\r\nGATEWAY=192.168.50.1<\/pre>\n<h4>For Ubuntu\/Debian\/Linux Mint<\/h4>\n<p>Assign Static IP Address to\u00a0<strong>eth0<\/strong>\u00a0interface editing configuration file\u00a0<strong>\/etc\/network\/interfaces<\/strong>\u00a0to make permanent changes as shown below.<\/p>\n<pre>auto eth0\r\niface eth0 inet static\r\naddress 192.168.50.2\r\nnetmask 255.255.255.0\r\ngateway 192.168.50.1<\/pre>\n<p>Next, restart network services after entering all the details using the following command.<\/p>\n<pre># \/etc\/init.d\/networking restart<\/pre>\n<pre>$ sudo \/etc\/init.d\/networking restart<\/pre>\n<h3>1. How to Assign a IP Address to Specific Interface<\/h3>\n<p>The following command used to assign IP Address to a specific interface (<strong>eth1<\/strong>) on the fly.<\/p>\n<pre># ip addr add 192.168.50.5 dev eth1<\/pre>\n<pre>$ sudo ip addr add 192.168.50.5 dev eth1<\/pre>\n<p><strong>Note:<\/strong>\u00a0Unfortunately all these settings will be lost after a system restart.<\/p>\n<h3>2. How to Check an IP Address<\/h3>\n<p>To get the depth information of your network interfaces like IP Address, MAC Address information, use the following command as shown below.<\/p>\n<pre># ip addr show<\/pre>\n<pre>$ sudo ip addr show<\/pre>\n<h5>Sample Output<\/h5>\n<pre>1: lo: &lt;LOOPBACK,UP,LOWER_UP&gt; mtu 16436 qdisc noqueue state UNKNOWN\r\n    link\/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00\r\n    inet 127.0.0.1\/8 scope host lo\r\n    inet6 ::1\/128 scope host\r\n       valid_lft forever preferred_lft forever\r\n2: eth0: &lt;BROADCAST,MULTICAST,UP,LOWER_UP&gt; mtu 1500 qdisc pfifo_fast state UNKNOWN qlen 1000\r\n    link\/ether 00:0c:29:28:fd:4c brd ff:ff:ff:ff:ff:ff\r\n    inet 192.168.50.2\/24 brd 192.168.50.255 scope global eth0\r\n    inet6 fe80::20c:29ff:fe28:fd4c\/64 scope link\r\n       valid_lft forever preferred_lft forever\r\n3: eth1: &lt;BROADCAST,MULTICAST,UP,LOWER_UP&gt; mtu 1500 qdisc pfifo_fast state UNKNOWN qlen 1000\r\n    link\/ether 00:0c:29:28:fd:56 brd ff:ff:ff:ff:ff:ff\r\n    inet 192.168.50.5\/24 scope global eth1\r\n    inet6 fe80::20c:29ff:fe28:fd56\/64 scope link\r\n       valid_lft forever preferred_lft forever<\/pre>\n<h3>3. How to Remove an IP Address<\/h3>\n<p>The following command will remove an assigned IP address from the given interface (<strong>eth1<\/strong>).<\/p>\n<pre># ip addr del 192.168.50.5\/24 dev eth1<\/pre>\n<pre>$ sudo ip addr del 192.168.50.5\/24 dev eth1<\/pre>\n<h3>4. How to Enable Network Interface<\/h3>\n<p>The \u201c<strong>up<\/strong>\u201d flag with interface name (<strong>eth1<\/strong>) enables a network interface. For example, the following command will activates the\u00a0<strong>eth1<\/strong>\u00a0network interface.<\/p>\n<pre># ip link set eth1 up<\/pre>\n<pre>$ sudo ip link set eth1 up<\/pre>\n<h3>5. How to Disable Network Interface<\/h3>\n<p>The \u201c<strong>down<\/strong>\u201d flag with interface name (<strong>eth1<\/strong>) disables a network interface. For example, the following command will De-activates the\u00a0<strong>eth1<\/strong>\u00a0network interface.<\/p>\n<pre># ip link set eth1 down<\/pre>\n<pre>$ sudo ip link set eth1 down<\/pre>\n<h3>6. How do I Check Route Table?<\/h3>\n<p>Type the following command to check the routing table information of system.<\/p>\n<pre># ip route show<\/pre>\n<pre>$ sudo ip route show<\/pre>\n<h5>Sample Output<\/h5>\n<pre>10.10.20.0\/24 via 192.168.50.100 dev eth0\r\n192.168.160.0\/24 dev eth1  proto kernel  scope link  src 192.168.160.130  metric 1\r\n192.168.50.0\/24 dev eth0  proto kernel  scope link  src 192.168.50.2\r\n169.254.0.0\/16 dev eth0  scope link  metric 1002\r\ndefault via 192.168.50.1 dev eth0  proto static<\/pre>\n<h3>7. How do I Add Static Route<\/h3>\n<p>Why you need to add Static routes or Manual routes, because that the traffic must not pass through the default gateway. We need to add Static routes to pass traffic from best way to reach the destination.<\/p>\n<pre># ip route add 10.10.20.0\/24 via 192.168.50.100 dev eth0<\/pre>\n<pre>$ sudo ip route add 10.10.20.0\/24 via 192.168.50.100 dev eth0<\/pre>\n<h3>8. How to Remove Static Route<\/h3>\n<p>To remove assigned static route, simply type the following command.<\/p>\n<pre># ip route del 10.10.20.0\/24<\/pre>\n<pre>$ sudo ip route del 10.10.20.0\/24<\/pre>\n<h3>9. How do I Add Persistence Static Routes<\/h3>\n<p>All the above route will be lost after a system restart. To add permanent Static route, edit file\u00a0<strong>\/etc\/sysconfig\/network-scripts\/route-eth0<\/strong>\u00a0(We are storing static route for (<strong>eth0<\/strong>) and add the following lines and save and exist. By default\u00a0<strong>route-eth0<\/strong>\u00a0file will not be there, need to be created.<\/p>\n<h4>For RHEL\/CentOS\/Fedora<\/h4>\n<pre># vi \/etc\/sysconfig\/network-scripts\/route-eth0\r\n10.10.20.0\/24 via 192.168.50.100 dev eth0<\/pre>\n<h4>For Ubuntu\/Debian\/Linux Mint<\/h4>\n<p>Open the file\u00a0<strong>\/etc\/network\/interfaces<\/strong>\u00a0and at the end add the persistence Static routes. IP Addresses may differ in your environment.<\/p>\n<pre>$ sudo vi \/etc\/network\/interfaces<\/pre>\n<pre>auto eth0\r\niface eth0 inet static\r\naddress 192.168.50.2\r\nnetmask 255.255.255.0\r\ngateway 192.168.50.100\r\n#########{<strong>Static Route<\/strong>}###########\r\nup ip route add 10.10.20.0\/24 via 192.168.50.100 dev eth0<\/pre>\n<p>Next, restart network services after entering all the details using the following command.<\/p>\n<pre># \/etc\/init.d\/network restart<\/pre>\n<pre>$ sudo \/etc\/init.d\/network restart<\/pre>\n<h3>10. How do I Add Default Gateway<\/h3>\n<p>Default gateway can be specified globally or for in interface-specific config file. Advantage of default gateway is If we have more than one NIC is present in the system. You can add default gateway on the fly as shown below command.<\/p>\n<pre># ip route add default via 192.168.50.100<\/pre>\n<pre>$ sudo ip route add default via 192.168.50.100<\/pre>\n<p>Kindly correct me if i missed out. Please refer manual page doing\u00a0<b>man ip<\/b>\u00a0from terminal\/command prompt to know more about IP Command.<\/p>\n<p><a href=\"https:\/\/www.tecmint.com\/ip-command-examples\/\" target=\"_blank\" rel=\"noopener\">Source<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this post, we are going to review how we can assign\u00a0Static IP Address,\u00a0Static Route,\u00a0Default Gateway\u00a0etc.\u00a0 Assigning IP Address on demand using\u00a0IP\u00a0command.\u00a0IFCONFIG command\u00a0is deprecated and replaced by\u00a0IPcommand in\u00a0Linux. However,\u00a0IFCONFIG\u00a0command is still works and available for most of the Linux distributions. Don\u2019t Miss:\u00a0ifconfig vs ip: What\u2019s Difference and Comparing Commands 10 IP Command Examples Note:\u00a0Please take &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.appservgrid.com\/paw92\/index.php\/2019\/03\/13\/10-useful-ip-commands-to-configure-network-interfaces\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;10 Useful \u201cIP\u201d Commands to Configure Network Interfaces&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-11310","post","type-post","status-publish","format-standard","hentry","category-linux"],"_links":{"self":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/11310","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/comments?post=11310"}],"version-history":[{"count":1,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/11310\/revisions"}],"predecessor-version":[{"id":11311,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/11310\/revisions\/11311"}],"wp:attachment":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/media?parent=11310"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/categories?post=11310"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/tags?post=11310"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}