{"id":996,"date":"2018-05-14T08:26:27","date_gmt":"2018-05-14T08:26:27","guid":{"rendered":"http:\/\/jaipurhosting.com\/blog\/?p=996"},"modified":"2019-04-27T11:51:39","modified_gmt":"2019-04-27T06:21:39","slug":"how-to-configure-network-interfaces-using-ip-commands-in-cent-os","status":"publish","type":"post","link":"https:\/\/www.jaipurhosting.com\/blog\/how-to-configure-network-interfaces-using-ip-commands-in-cent-os\/","title":{"rendered":"How to Configure Network Interfaces using IP Commands in cent os"},"content":{"rendered":"<p><strong>Description&nbsp;<\/strong><\/p>\n<p>We are going to review how we can assign Static IP Address, Static Route, Default Gateway etc.<\/p>\n<p>Assigning IP Address on demand using IP command.<\/p>\n<p>IFCONFIG command is deprecated and replaced by IP command in Linux.<\/p>\n<p>However, IFCONFIG command is still works and available for most of the Linux distributions.<\/p>\n<p>&nbsp;<\/p>\n<p><strong>Configure of Static IP Address Internet Protocol (IPv4)&nbsp;<\/strong><\/p>\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.<\/p>\n<p>You must be superuser with su (switch user) command from terminal or command prompt.<\/p>\n<p>Open and edit network configuration file for (eth0 or eth1) using your favorite editor.<\/p>\n<p>For example, to assigning IP Address to eth0 interface as follows.<\/p>\n<pre class=\"theme:dark-terminal lang:default decode:true\">[root@vps ~]# vi \/etc\/sysconfig\/network-scripts\/ifcfg-eth0\n<\/pre>\n<p><strong>Simple output<\/strong><\/p>\n<pre class=\"theme:dark-terminal lang:default decode:true \">DEVICE=\"eth0\"\nBOOTPROTO=static\nONBOOT=yes\nTYPE=\"Ethernet\"\nIPADDR=192.168.50.2\nNAME=\"System eth0\"\nHWADDR=00:0C:29:28:FD:4C\nGATEWAY=192.168.50.1<\/pre>\n<p>&nbsp;<\/p>\n<p><strong>Step 1<\/strong> : How to Assign a IP Address to Specific Interface<\/p>\n<p>The following command used to assign IP Address to a specific interface (eth1) on the fly.<\/p>\n<pre class=\"theme:dark-terminal lang:default decode:true\"># ip addr add 192.168.50.5 dev eth1<\/pre>\n<pre class=\"theme:dark-terminal lang:default decode:true \">$ sudo ip addr add 192.168.50.5 dev eth1<\/pre>\n<p><strong>Note<\/strong>: Unfortunately all these settings will be lost after a system restart.<\/p>\n<p>&nbsp;<\/p>\n<p><strong>Step 2<\/strong> : How to Check an IP Address<\/p>\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 class=\"theme:dark-terminal lang:default decode:true \"># ip addr show<\/pre>\n<pre class=\"theme:dark-terminal lang:default decode:true \">$ sudo ip addr show<\/pre>\n<p><strong>Sample Output<\/strong><\/p>\n<pre class=\"theme:dark-terminal lang:default decode:true \">1: lo: &lt;LOOPBACK,UP,LOWER_UP&gt; mtu 16436 qdisc noqueue state UNKNOWN\nlink\/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00\ninet 127.0.0.1\/8 scope host lo\ninet6 ::1\/128 scope host\nvalid_lft forever preferred_lft forever\n2: eth0: &lt;BROADCAST,MULTICAST,UP,LOWER_UP&gt; mtu 1500 qdisc pfifo_fast state UNKNOWN qlen 1000\nlink\/ether 00:0c:29:28:fd:4c brd ff:ff:ff:ff:ff:ff\ninet 192.168.50.2\/24 brd 192.168.50.255 scope global eth0\ninet6 fe80::20c:29ff:fe28:fd4c\/64 scope link\nvalid_lft forever preferred_lft forever\n3: eth1: &lt;BROADCAST,MULTICAST,UP,LOWER_UP&gt; mtu 1500 qdisc pfifo_fast state UNKNOWN qlen 1000\nlink\/ether 00:0c:29:28:fd:56 brd ff:ff:ff:ff:ff:ff\ninet 192.168.50.5\/24 scope global eth1\ninet6 fe80::20c:29ff:fe28:fd56\/64 scope link\nvalid_lft forever preferred_lft forever<\/pre>\n<p>&nbsp;<\/p>\n<p><strong>Step 3<\/strong> : How to Remove an IP Address<\/p>\n<p>The following command will remove an assigned IP address from the given interface (eth1).<\/p>\n<pre class=\"theme:dark-terminal lang:default decode:true \"># ip addr del 192.168.50.5\/24 dev eth1<\/pre>\n<pre class=\"theme:dark-terminal lang:default decode:true \">$ sudo ip addr del 192.168.50.5\/24 dev eth1<\/pre>\n<p>&nbsp;<\/p>\n<p><strong>Step 4<\/strong> : How to Enable Network Interface<\/p>\n<p>The \u201cup\u201d flag with interface name (eth1) enables a network interface.<\/p>\n<p>For example, the following command will activates the eth1 network interface.<\/p>\n<pre class=\"theme:dark-terminal lang:default decode:true \"># ip link set eth1 up<\/pre>\n<pre class=\"theme:dark-terminal lang:default decode:true \">$ sudo ip link set eth1 up<\/pre>\n<p>&nbsp;<\/p>\n<p><strong>Step 5<\/strong> : How to Disable Network Interface<\/p>\n<p>The \u201cdown\u201d flag with interface name (eth1) disables a network interface.<\/p>\n<p>For example, the following command will De-activates the eth1 network interface.<\/p>\n<pre class=\"theme:dark-terminal lang:default decode:true \"># ip link set eth1 down<\/pre>\n<pre class=\"theme:dark-terminal lang:default decode:true \">$ sudo ip link set eth1 down<\/pre>\n<p>&nbsp;<\/p>\n<p><strong>Step 6<\/strong> : How to Check Route Table<\/p>\n<p>Type the following command to check the routing table information of system.<\/p>\n<pre class=\"theme:dark-terminal lang:default decode:true \"># ip route show<\/pre>\n<pre class=\"theme:dark-terminal lang:default decode:true \">$ sudo ip route show<\/pre>\n<p><strong>Sample Output<\/strong><\/p>\n<pre class=\"theme:dark-terminal lang:default decode:true \">10.10.20.0\/24 via 192.168.50.100 dev eth0\n192.168.160.0\/24 dev eth1 proto kernel scope link src 192.168.160.130 metric 1\n192.168.50.0\/24 dev eth0 proto kernel scope link src 192.168.50.2\n169.254.0.0\/16 dev eth0 scope link metric 1002\ndefault via 192.168.50.1 dev eth0 proto static<\/pre>\n<p><strong>Step 7<\/strong> : How do I Add Static Route<\/p>\n<p>Why you need to add Static routes or Manual routes, because that the traffic must not pass through the default gateway.<\/p>\n<p>We need to add Static routes to pass traffic from best way to reach the destination..<\/p>\n<pre class=\"theme:dark-terminal lang:default decode:true \"># ip route add 10.10.20.0\/24 via 192.168.50.100 dev eth0<\/pre>\n<pre class=\"theme:dark-terminal lang:default decode:true \">$ sudo ip route add 10.10.20.0\/24 via 192.168.50.100 dev eth0<\/pre>\n<p>&nbsp;<\/p>\n<p><strong>Step 8<\/strong> : How to Remove Static Route<\/p>\n<p>To remove assigned static route, simply type the following command.<\/p>\n<pre class=\"theme:dark-terminal lang:default decode:true \"># ip route del 10.10.20.0\/24<\/pre>\n<pre class=\"theme:dark-terminal lang:default decode:true \">$ sudo ip route del 10.10.20.0\/24<\/pre>\n<p>&nbsp;<\/p>\n<p><strong>Step 9<\/strong> : How do I Add Persistence Static Routes<\/p>\n<p>All the above route will be lost after a system restart.<\/p>\n<p>To add permanent Static route, edit file <strong>\/etc\/sysconfig\/network-scripts\/route-eth0<\/strong> (We are storing static route for (eth0) and add the following lines and save and exist.<\/p>\n<p>By default route-eth0 file will not be there, need to be created.<\/p>\n<pre class=\"theme:dark-terminal lang:default decode:true \"># vi \/etc\/sysconfig\/network-scripts\/route-eth0\n10.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 class=\"theme:dark-terminal lang:default decode:true \"># \/etc\/init.d\/network restart<\/pre>\n<p>&nbsp;<\/p>\n<p><strong>Step 10<\/strong> : How do I Add Default Gateway<\/p>\n<p>Default gateway can be specified globally or for in interface-specific config file.<\/p>\n<p>Advantage of default gateway is If we have more than one NIC is present in the system.<\/p>\n<p>You can add default gateway on the fly as shown below command.<\/p>\n<pre class=\"theme:dark-terminal lang:default decode:true \"># ip route add default via 192.168.50.100<\/pre>\n<pre class=\"theme:dark-terminal lang:default decode:true \">$ sudo ip route add default via 192.168.50.100<\/pre>\n<p>&nbsp;<\/p>\n<p>We hope you\u2019ve found this useful!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Description&nbsp; We are going to review how we can assign Static IP Address, Static Route, Default Gateway etc. Assigning IP Address on demand using IP command. IFCONFIG command is deprecated and replaced by IP command in Linux. However, IFCONFIG command is still works and available for most of the Linux distributions. &nbsp; Configure of Static [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":1304,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-996","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-categorized"],"_links":{"self":[{"href":"https:\/\/www.jaipurhosting.com\/blog\/wp-json\/wp\/v2\/posts\/996","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.jaipurhosting.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.jaipurhosting.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.jaipurhosting.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.jaipurhosting.com\/blog\/wp-json\/wp\/v2\/comments?post=996"}],"version-history":[{"count":2,"href":"https:\/\/www.jaipurhosting.com\/blog\/wp-json\/wp\/v2\/posts\/996\/revisions"}],"predecessor-version":[{"id":1552,"href":"https:\/\/www.jaipurhosting.com\/blog\/wp-json\/wp\/v2\/posts\/996\/revisions\/1552"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.jaipurhosting.com\/blog\/wp-json\/wp\/v2\/media\/1304"}],"wp:attachment":[{"href":"https:\/\/www.jaipurhosting.com\/blog\/wp-json\/wp\/v2\/media?parent=996"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.jaipurhosting.com\/blog\/wp-json\/wp\/v2\/categories?post=996"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.jaipurhosting.com\/blog\/wp-json\/wp\/v2\/tags?post=996"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}