Linux Red Hat Network Related Commands
Check IP Address
# ifconfig Display IP Address, mask
& MTU
# ifconfig –a Display
IP Address, mask & MTU
# ip addr show Display IP Address, mask
& MTU
Find default gateway
# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 192.168.2.1 0.0.0.0 UG
100 0 0 eno16777736
192.168.2.0
0.0.0.0 255.255.255.0 U
100 0 0 eno16777736
192.168.122.0
0.0.0.0 255.255.255.0 U
0 0 0 virbr0
[root@linux1 ~]#
# route -n | grep 'UG[ \t]' | awk
'{print $2}'
# netstat -rn
Kernel IP routing table
Destination
Gateway Genmask Flags
MSS Window irtt Iface
0.0.0.0
192.168.2.1 0.0.0.0 UG 0 0 0 eno16777736
192.168.2.0
0.0.0.0 255.255.255.0 U
0 0 0 eno16777736
192.168.122.0
0.0.0.0 255.255.255.0 U
0 0 0 virbr0
#
# ip route show
default via 192.168.2.1 dev eno16777736 proto static
metric 100
192.168.2.0/24 dev eno16777736 proto kernel
scope link src 192.168.2.50 metric 100
192.168.122.0/24 dev virbr0 proto kernel
scope link src 192.168.122.1
#
# cat
/etc/sysconfig/network-scripts/ifcfg-eno16777736
TYPE="Ethernet"
BOOTPROTO="none"
DEFROUTE="yes"
IPV4_FAILURE_FATAL="no"
IPV6INIT="yes"
IPV6_AUTOCONF="yes"
IPV6_DEFROUTE="yes"
IPV6_FAILURE_FATAL="no"
NAME="eno16777736"
UUID="19e3dc1b-7d48-4aa6-b26d-706e36057187"
DEVICE="eno16777736"
ONBOOT="yes"
IPADDR="192.168.2.50"
PREFIX="24"
GATEWAY="192.168.2.1"
DNS1="192.168.2.1"
IPV6_PEERDNS="yes"
IPV6_PEERROUTES="yes"
IPV6_PRIVACY="no"
[root@linux1 ~]#
Stop/Start/Restart Network Services RHEL 7.X
# systemctl restart network
# systemctl stop network
# systemctl start network
# systemctl status network
# service network restart RHEL 6.X
Bring network Adapter up/down
# ifconfig eno16777736 up
# ifconfig eno16777736 down Note: Make sure you have console Access.
# ip link set eno16777736 up
# ip link set eno16777736 down Note: Make sure you have console Access.
nmcli
nmcli is a command‐line tool for controlling NetworkManager
and reporting network status. It can be utilized as a replacement for nm‐applet
or other graphical clients. nmcli is used to create, display, edit, delete,
activate, and deactivate network connections, as well as control and display
network device status.
# nmcli connection
NAME
UUID
TYPE DEVICE
virbr0-nic 7886fc6b-b36a-4365-a406-6a8574d9bd2e generic virbr0-nic
virbr0
b66eec2a-32f3-4dc4-a6db-609777ef8284
bridge virbr0
eno16777736 19e3dc1b-7d48-4aa6-b26d-706e36057187 802-3-ethernet eno16777736
#
# nmcli con up eno16777736
Connection successfully activated (D-Bus active path:
/org/freedesktop/NetworkManager/ActiveConnection/4)
#
Note:
Make sure you have console access.
# nmcli con down eno16777736
Connection successfully activated (D-Bus active path:
/org/freedesktop/NetworkManager/ActiveConnection/4)
[root@linux1 ~]#
# nmcli general status
STATE
CONNECTIVITY WIFI-HW WIFI
WWAN-HW WWAN
connected
full enabled enabled
enabled enabled
#
# nmcli general logging
LEVEL DOMAINS
INFO
PLATFORM,RFKILL,ETHER,WIFI,BT,MB,DHCP4,DHCP6,PPP,IP4,IP6,AUTOIP4,DNS,VPN,SHARING,SUPPLICANT,AGENTS,SETTINGS,SUSPEND,CORE,DEVICE,OLPC,WIMAX,INFINIBAND,FIREWALL,ADSL,BOND,VLAN,BRIDGE,TEAM,CONCHECK,DCB,DISPATCH
[root@linux1 ~]#
# nmcli device status
DEVICE
TYPE STATE CONNECTION
virbr0
bridge connected virbr0
eno16777736
ethernet connected eno16777736
virbr0-nic
tap connected virbr0-nic
lo
loopback unmanaged --
[root@linux1 ~]#
# nmcli con edit
Nmtui (Change Network IP/hostname permanently).
nmtui - Text User
Interface for controlling NetworkManager
Note: Make sure you
console access as you have to activate/deactivate network connection..
[root@linux1 ~]# nmtui Change IP/Gateway/Mask and hostname
Configuring a Network Interface Using ip Commands
Syntax
ip addr [ add |
del ] address dev ifname
Configuring a Network Interface Using ifconfig commands
Note: using ifconfig, network change will be temporary
and will lost after server reboot.
# ifconfig eno16777736 192.168.2.50
netmask 255.255.255.0 up
You can verify you IP address either change temporarily or
permanently.
# cat
/etc/sysconfig/network-scripts/ifcfg-eno16777736
Verify your gateway
# route -n
Note: As soon as you restart the
Network services or reboot the computer, your old IP Address will come back.
# systemctl restart network
Modify an IP Address Permanently
# ifconfig
# vi
/etc/sysconfig/network-scripts/ifcfg-eno16777736
TYPE="Ethernet"
BOOTPROTO="none"
DEFROUTE="yes"
IPV4_FAILURE_FATAL="no"
IPV6INIT="yes"
IPV6_AUTOCONF="yes"
IPV6_DEFROUTE="yes"
IPV6_FAILURE_FATAL="no"
NAME="eno16777736"
UUID="19e3dc1b-7d48-4aa6-b26d-706e36057187"
DEVICE="eno16777736"
ONBOOT="yes"
DNS1="192.168.2.1"
IPADDR=192.168.2.53
PREFIX=24
GATEWAY=192.168.2.1
IPV6_PEERDNS=yes
IPV6_PEERROUTES=yes
IPV6_PRIVACY=no
# systemctl restart network
Configure DNS
# cat /etc/resolv.conf
# Generated by NetworkManager
nameserver 192.168.2.1
#
