Difference between revisions of "CLI - Networking"

Line 1: Line 1:
Both IPv4 and IPv6 addresses can be configured in the configuration mode.
+
Both IPv4 and IPv6 addresses can be configured in the configuration mode. To display network interfaces and their assigned addresses, type the <code>show interface</code>
 
<pre>
 
<pre>
LYSH@MyHostName# configure
+
LYSH@MyHostName# show interface
configure# ip add -h
+
lo:
usage: ip add [-h] interface ip [gateway]
+
    stats          : operate=up, up=yes, speed=0MB, duplex=?, mtu=65536
 +
    incoming      : bytes=79.3G, pkts=310057073, errs=0, drops=0
 +
    outgoing      : bytes=79.3G, pkts=310057073, errs=0, drops=0
 +
    IPv4 address  : 127.0.0.1/8
 +
    IPv6 address  : ::1/128
 +
    MAC  address  : 00:00:00:00:00:00
  
positional arguments:
+
eth0:
  interface  Ethernet interface name
+
    stats          : operate=up, up=yes, speed=100MB, duplex=full, mtu=1500
  ip          IPv4/Subnet Mask or IPv6 address/prefix
+
    incoming      : bytes=15.1G, pkts=93920605, errs=0, drops=6869214
   [gateway]  IPv4 or IPv6 address
+
    outgoing      : bytes=65.9G, pkts=76383487, errs=0, drops=0
 +
    gateway4      : 192.168.0.1
 +
    IPv4 address   : 192.168.0.40/24
 +
    MAC  address   : 00:01:a2:92:1e:f3
  
optional arguments:
+
LYSH@MyHostName# show interface eth0 // Display only eth0
   -h, --help show this help message and exit
+
eth0:
 +
    stats          : operate=up, up=yes, speed=100MB, duplex=full, mtu=1500
 +
    incoming      : bytes=15.1G, pkts=93920605, errs=0, drops=6869214
 +
    outgoing      : bytes=65.9G, pkts=76383487, errs=0, drops=0
 +
    gateway4      : 192.168.0.1
 +
    IPv4 address   : 192.168.0.40/24
 +
    MAC address  : 00:01:a2:92:1e:f3
 
</pre>
 
</pre>
 +
  
 
=== Configuring new IP addresses ===
 
=== Configuring new IP addresses ===
Line 19: Line 34:
 
configure# ip add eth0 192.168.0.3/24 192.168.0.1 // Configures an IPv4 address, subnet, and gateway.(i.e. 192.168.0.1)
 
configure# ip add eth0 192.168.0.3/24 192.168.0.1 // Configures an IPv4 address, subnet, and gateway.(i.e. 192.168.0.1)
 
configure# ip add eth0 2000:4::40/64 2000:4::1 // Configures an IPv6 address, prefix, and gateway.(i.e, 2000:4::1)
 
configure# ip add eth0 2000:4::40/64 2000:4::1 // Configures an IPv6 address, prefix, and gateway.(i.e, 2000:4::1)
configure# netplan apply // immediately apply the configurations.
+
interface setting was added. Do you want to apply these settings?(y/n): y // immediately apply the configurations.
 
configure# exit
 
configure# exit
 
configure# show interface
 
configure# show interface
Line 25: Line 40:
 
LYSH@MyHostName# ping6 2000:4::1
 
LYSH@MyHostName# ping6 2000:4::1
 
</pre>
 
</pre>
 +
Note that, If a network interface already has an assigned IP address and you configure another IP address and gateway of the same version, the gateway is ignored. In the words, the secondary gateway of the same version is not allowed.
 +
  
 
=== Deleting an IP addresses ===
 
=== Deleting an IP addresses ===
Line 31: Line 48:
 
configure# ip delete eth0 192.168.0.3/24 // Deletes an IPv4 address(i.e. 192.168.0.3/24)
 
configure# ip delete eth0 192.168.0.3/24 // Deletes an IPv4 address(i.e. 192.168.0.3/24)
 
configure# ip delete eth0 2000:4::40/64 // Deletes an IPv6 address(i.e. 2000:4::40/64)
 
configure# ip delete eth0 2000:4::40/64 // Deletes an IPv6 address(i.e. 2000:4::40/64)
configure# netplan apply // immediately apply the configurations.
+
interface setting was deleted. Do you want to apply these settings?(y/n): y // immediately apply the configurations.
 
configure# exit
 
configure# exit
 
configure# show interface
 
configure# show interface
 
</pre>
 
</pre>
 +
Note that, If a network interface has multiple assigned IP addresses of the same version(i.e. IPv4 or IPv6), the gateway address is not removing before deleting all IP addresses of the same version from a network interface.

Revision as of 15:04, 20 April 2021

Both IPv4 and IPv6 addresses can be configured in the configuration mode. To display network interfaces and their assigned addresses, type the show interface

LYSH@MyHostName# show interface
lo:
    stats          : operate=up, up=yes, speed=0MB, duplex=?, mtu=65536
    incoming       : bytes=79.3G, pkts=310057073, errs=0, drops=0
    outgoing       : bytes=79.3G, pkts=310057073, errs=0, drops=0
    IPv4 address   : 127.0.0.1/8
    IPv6 address   : ::1/128
    MAC  address   : 00:00:00:00:00:00

eth0:
    stats          : operate=up, up=yes, speed=100MB, duplex=full, mtu=1500
    incoming       : bytes=15.1G, pkts=93920605, errs=0, drops=6869214
    outgoing       : bytes=65.9G, pkts=76383487, errs=0, drops=0
    gateway4       : 192.168.0.1
    IPv4 address   : 192.168.0.40/24 
    MAC  address   : 00:01:a2:92:1e:f3

LYSH@MyHostName# show interface eth0			// Display only eth0
eth0:
    stats          : operate=up, up=yes, speed=100MB, duplex=full, mtu=1500
    incoming       : bytes=15.1G, pkts=93920605, errs=0, drops=6869214
    outgoing       : bytes=65.9G, pkts=76383487, errs=0, drops=0
    gateway4       : 192.168.0.1
    IPv4 address   : 192.168.0.40/24 
    MAC  address   : 00:01:a2:92:1e:f3


Configuring new IP addresses

LYSH@MyHostName# configure				// Enters configuration mode.
configure# ip add eth0 192.168.0.3/24 192.168.0.1	// Configures an IPv4 address, subnet, and gateway.(i.e. 192.168.0.1)
configure# ip add eth0 2000:4::40/64 2000:4::1		// Configures an IPv6 address, prefix, and gateway.(i.e, 2000:4::1)
interface setting was added. Do you want to apply these settings?(y/n): y	// immediately apply the configurations.
configure# exit
configure# show interface
LYSH@MyHostName# ping 192.168.0.1		
LYSH@MyHostName# ping6 2000:4::1				

Note that, If a network interface already has an assigned IP address and you configure another IP address and gateway of the same version, the gateway is ignored. In the words, the secondary gateway of the same version is not allowed.


Deleting an IP addresses

LYSH@MyHostName# configure				// Enters configuration mode.
configure# ip delete eth0 192.168.0.3/24		// Deletes an IPv4 address(i.e. 192.168.0.3/24)
configure# ip delete eth0 2000:4::40/64			// Deletes an IPv6 address(i.e. 2000:4::40/64)
interface setting was deleted. Do you want to apply these settings?(y/n): y	// immediately apply the configurations.
configure# exit
configure# show interface				

Note that, If a network interface has multiple assigned IP addresses of the same version(i.e. IPv4 or IPv6), the gateway address is not removing before deleting all IP addresses of the same version from a network interface.