What is the name of command line utility that is used to display and manage IP address assigned to a machine?

The ip command is a new networking command-line utility that is used to assign an IP address to a network interface or configure/update useful network variables on a Linux system.

It is a part of the iproute2 package and offers several network administration tasks such as bringing up or down network interfaces, assign and remove IP addresses and routes, manage ARP cache, and much more.

The ip command is much similar to the old ifconfig command, but it is greatly more powerful with more functions and capabilities added to it.

[ You might also like: Deprecated Linux Networking Commands and Their Replacements ]

The ifconfig command has been deprecated and replaced by the ip command in all modern Linux distributions. However, the ifconfig command is still works and available for most Linux distributions.

[ You might also like: ifconfig vs ip: What’s Difference and Comparing Network Configuration ]

10 IP Command Examples

Note: Please take configuration file backup before doing any changes.

How Do I Configure Static IP Address Internet Protocol (IPv4)

To configure static IP Addresses in Linux, you need to update or edit the network configuration file to assign a Static IP Address to a system. You must be a superuser with a su (switch user) command from the terminal or command prompt.

For RHEL/CentOS/Fedora and Rocky Linux/AlmaLinux

Open and edit the network configuration files for (eth0 or eth1) using your favorite text editor. For example, assigning IP Address to eth0 interface as follows.

[[email protected] ~]# vi /etc/sysconfig/network-scripts/ifcfg-eth0 Simple output: DEVICE="eth0" BOOTPROTO=static ONBOOT=yes TYPE="Ethernet" IPADDR=192.168.50.2 NAME="System eth0" HWADDR=00:0C:29:28:FD:4C GATEWAY=192.168.50.1

For Ubuntu/Debian/Linux Mint

Assign Static IP Address to eth0 interface editing configuration file /etc/network/interfaces to make permanent changes as shown below.

auto eth0 iface eth0 inet static address 192.168.50.2 netmask 255.255.255.0 gateway 192.168.50.1

Next, restart network services after entering all the details using the following command.

# systemctl restart NetworkManager.service Or # /etc/init.d/networking restart

[ You might also like: How to Configure Network Connection Using ‘nmcli’ Tool ]

1. How to Assign an IP Address to a Specific Interface

The following command is used to assign an IP Addresses to a specific interface (eth1) on the fly.

# ip addr add 192.168.50.5 dev eth1 $ sudo ip addr add 192.168.50.5 dev eth1

Note: Unfortunately all these settings will be lost after a system restart.

2. How to Check an IP Address

To get the depth information of your network interfaces like IP Address, MAC Address information, use the following command as shown below.

# ip addr show $ sudo ip addr show Sample Output 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state UNKNOWN link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo inet6 ::1/128 scope host valid_lft forever preferred_lft forever 2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UNKNOWN qlen 1000 link/ether 00:0c:29:28:fd:4c brd ff:ff:ff:ff:ff:ff inet 192.168.50.2/24 brd 192.168.50.255 scope global eth0 inet6 fe80::20c:29ff:fe28:fd4c/64 scope link valid_lft forever preferred_lft forever 3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UNKNOWN qlen 1000 link/ether 00:0c:29:28:fd:56 brd ff:ff:ff:ff:ff:ff inet 192.168.50.5/24 scope global eth1 inet6 fe80::20c:29ff:fe28:fd56/64 scope link valid_lft forever preferred_lft forever

3. How to Remove an IP Address

The following command will remove an assigned IP address from the given interface (eth1).

# ip addr del 192.168.50.5/24 dev eth1 $ sudo ip addr del 192.168.50.5/24 dev eth1

4. How to Enable Network Interface

The “up” flag with interface name (eth1) enables a network interface. For example, the following command will activate the eth1 network interface.

# ip link set eth1 up $ sudo ip link set eth1 up

5. How to Disable Network Interface

The “down” flag with interface name (eth1) disables a network interface. For example, the following command will De-activates the eth1 network interface.

# ip link set eth1 down $ sudo ip link set eth1 down

6. How do I Check Route Table?

Type the following command to check the routing table information of the system.

# ip route show $ sudo ip route show Sample Output 10.10.20.0/24 via 192.168.50.100 dev eth0 192.168.160.0/24 dev eth1 proto kernel scope link src 192.168.160.130 metric 1 192.168.50.0/24 dev eth0 proto kernel scope link src 192.168.50.2 169.254.0.0/16 dev eth0 scope link metric 1002 default via 192.168.50.1 dev eth0 proto static

7. How do I Add Static Route

Why do 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 the best way to reach the destination.

# ip route add 10.10.20.0/24 via 192.168.50.100 dev eth0 $ sudo ip route add 10.10.20.0/24 via 192.168.50.100 dev eth0

8. How to Remove Static Route

To remove the assigned static route, simply type the following command.

# ip route del 10.10.20.0/24 $ sudo ip route del 10.10.20.0/24

9. How do I Add Persistence Static Routes

All the above routes will be lost after a system restart. To add permanent Static route, edit file /etc/sysconfig/network-scripts/route-eth0 (We are storing static route for (eth0).

For RHEL/CentOS/Fedora and Rocky Linux/AlmaLinux

# vi /etc/sysconfig/network-scripts/route-eth0

and add the following lines and save and exit. By default route-eth0 file will not be there, need to be created.

10.10.20.0/24 via 192.168.50.100 dev eth0

For Ubuntu/Debian/Linux Mint

Open the file /etc/network/interfaces and at the end add the persistence Static routes. IP Addresses may differ in your environment.

$ sudo vi /etc/network/interfaces auto eth0 iface eth0 inet static address 192.168.50.2 netmask 255.255.255.0 gateway 192.168.50.100 #########{Static Route}########### up ip route add 10.10.20.0/24 via 192.168.50.100 dev eth0

Next, restart network services after entering all the details using the following command.

# systemctl restart NetworkManager.service Or # /etc/init.d/networking restart

10. How do I Add Default Gateway

The default gateway can be specified globally or for interface-specific config files. The advantage of the default gateway is If we have more than one NIC is present in the system. You can add the default gateway on the fly as shown below the command.

# ip route add default via 192.168.50.100 $ sudo ip route add default via 192.168.50.100

Kindly correct me if I missed out. Please refer manual page doing man ip from terminal/command prompt to know more about IP Command.

TecMint is the fastest growing and most trusted community site for any kind of Linux Articles, Guides and Books on the web. Millions of people visit TecMint! to search or browse the thousands of published articles available FREELY to all.

If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.

We are thankful for your never ending support.

If you are thinking of becoming a system administrator, or you are already a system admin, then this article is for you.

As a system admin, your daily routine will include configuring, maintaining, troubleshooting, monitoring, securing networks, and managing servers within data centers. Network configuration and troubleshooting are some important tasks that system admin know to perform.

Sometimes networked systems fail and you as a system admin have to diagnose and resolve the problems. So when it comes to Linux,  you as a system admin would get access to numerous tools and utilities in Linux, designed for administrative purposes that we are going to discuss 13 of them today in this article.

Network Configuration, Troubleshooting and Debugging Tools

1. ifconfig Command:

Ifconfig is a system administration utility for network interface configuration in Linux that is used to initialize interfaces at system boot time. Features like configuring, controlling, and querying TCP/IP network interface parameters are available in ifconfig. Setting up the IP address and netmask of any network interface and disabling or enabling any interface are some usages of ifconfig .

The status of IP Address, Hardware / MAC address and MTU (Maximum Transmission Unit) size of the currently active interfaces can be viewed

The status of all active network interfaces can be seen using the following command:-

$ ifconfig

For listing all interfaces currently available, whether up or down, use the -a flag. like this:

$ ifconfig -a

For assigning an IP address to an interface, run the following command:

$ sudo ifconfig eth0 195.167.54.6 netmask 255.255.255.0

For activating a network interface, use the following command:

$ sudo ifconfig up eth0

For deactivating or shutting down a network interface, run the following command:

$ sudo ifconfig down eth0

2.  Ethtool Command:

Ethtool is another command-line utility for displaying and modifying network interface controllers (NICs) parameters & device driver software. This tool is also useful for identifying & diagnosing  Ethernet devices, upgrading firmware in flash memory, etc.

For displaying the current parameters for the network interface, use the following command:-

ethtool [network interface]

3. IP Command :

IP command is kind of a replacement of ifconfig command. This command is used to perform different network administration tasks. This command is used to display or manipulate routing, devices, network devices, and tunnels. Although it is similar to ifconfig command but way too powerful including more functions and facilities in it. 

To display the IP address and other information about a network interface using the following command:-

$ ip addr show

For temporarily assigning IP Address to a specific network interface (eth0), use the following command:-

$ sudo ip addr add 195.162.54.2 dev eth0

For removing an assigned IP address from a network interface (eth0), use the following command:-

$ sudo ip addr del 195.162.54.15/24 dev eth0

Display the current neighbor table in the kernel, use the following command:-

$ ip neigh

4.  ifup, ifdown, and ifquery command:

Ifup command, in general, brings the network interface up, which allows the user to transmit and receive data by using the following command:

$ sudo ifup eth0

Ifup command, in general, brings the network interface down, which doesn’t allow the user to transmit and receive data by using the following command:

$ sudo ifdown eth0

To display information about a network interface’s configuration we use ifquery command by using the following command:

sudo ifquery eth0

5. Ping Command:

Ping(Packet INternet Groper)  command is a computer network administration software utility to test the reachability between two systems on Local Area Network (LAN) or Wide Area Network (WAN).

For communicating to nodes on a network ping sends Internet Control Message Protocol (ICMP) echo request packets to the targeted host and waits for an ICMP echo reply showing the ping is successful.

For testing connectivity to another node, we have to provide the Ip address /hostname, Syntax look like this:

IPv4: ping <ip address> / <host name> IPv6: ping6 <ip address> / <host name>

By using the -c flag you can also tell ping to exit after a specified number of ECHO_REQUEST packets as follows:

6. Netstat Command:

netstat is a command-line utility used for getting useful information regarding network connections, routing tables, interface statistics. It is also very useful for finding problems in the network and troubleshooting them and also determines the amount of traffic on the network.

As netstat is a network service debugging tool, it is used to check which programs are listening on what ports. To check which program is listening on what port by displaying all TCP ports in listening mode, use the following command:

$ sudo netstat -tnlp

For viewing the kernel routing table, we have to use the -r flag ( equivalent to the running route command that we discussed).

For displaying all ports; (for specifying only TCP use -at, for UDP use -au) use the following command:

$ netstat -a

For displaying transmission/receive (TX/RX) packet statistics for each interface using the -i flag

7. NC Command:

NC (NetCat) is a great security tool or network monitoring tool utility which is often referred to as a Swiss army knife of networking tools. 

It is used for reading from and writing to network connections using TCP or UDP. It has some remarkable features that include port scanning, transferring files, and port listening, and it can be used as a backdoor by hackers.

Netcat (nc) implied with Pv command together can be used to transfer files between two computers.

For performing Port Scanning. Run the following command:-

$netcat -z -v 127.0.0.1 1234 (Scanning a single port) $nc -z -v 127.0.0.1 1234 1235 (Scanning multiple ports) $nc -z -v 127.0.0.1 1233-1240 (Scanning a range of ports)

To send an HHTP on any website, suppose here I am sending it on GeeksforGeeks, then use the following command:-

printf “GET /nc.1 HTTPs/1.1\r\nHost: www.geeksforgeeks.org\r\n\r\n” | nc www.geeksforgeeks.org 80

8. Nmap Command:

Nmap (Network Mapper) is a  powerful free and open-source network scanner for Linux system/network administrators. To discover hosts and services on a computer network, Nmap is used by sending packets. Nmap features include Port scanning, detects MAC addresses, Version detection, OS detection, Network inventory, network mapping, etc.

We can scan a host using its hostname or IP address, by using the following command:-

nmap google.com nmap <ip address>

9.  NSLookup Command:

Nslookup ( “Name Server Lookup”) is a network administration command-line tool to query DNS servers both interactively and non-interactively to obtain domain name or IP address mapping, and DNS resource records (RR).

IP Address of the domain will be displayed after writing the following command:-

$ nslookup [domain name]

 We can also perform a reverse domain-lookup by using the following command:-

$ nslookup [ip address]

 

16. dig Command:

dig (domain information groper) command-line tool for querying the Domain Name System. NS-related information such as A Record, CNAME, MX Record, etc is retrieved using this command. NsLookup and host command are replaced by dig command.

10. Tcpdump Command

Tcpdump is a powerful data-network packet analyzer It is used for capturing network traffic in packets that are transmitted or received. System Administrators use this command to troubleshoot connectivity issues in Linux. Tcpdump listens to the network traffic and prints packet information that is based on the different criteria given by us about specific ports, protocols, etc. Captured information is saved in a pcap file, that can be then opened through Wireshark or through the tcpdump command itself.

Syntax: tcpdump -i <interface-name> [ live packets from the specified interface will be displayed.] tcpdump -i <interface> src <source-ip>[ packets are captured from a particular source IP.] tcpdump -i <interface> dst <destination-ip> [packets are captured from a particular destination IP.] tcpdump -c 5 -i <interface name> [ capture a specific number of packets] tcpdump -w captured.pacs -i <interface name> [ capture and save packets to a file ]

11. Wireshark Utility:

Wireshark is a great utility to capture and analyzing packets in GUI mode in real-time. Wireshark is considered very important as a networking-related professional. The captured data can be saved for later inspection. 

12. Iptables Firewall:

iptables is a firewall-like packet-filtering utility used by the system administrator for configuring, maintaining, and inspecting the IP packet filter rules of the Linux kernel firewall.  Linux firewall (Netfilter) is set up and managed by iptables. Iptables allow you to add or delete or modify packet filter rules in the existing packet filter rules.

Syntax: iptables -L (lists of all the existing iptables rules.) iptables -A INPUT -i <interface> -p tcp –dport <port-number> -m state –state NEW,ESTABLISHED -j ACCEPT ( it will allow traffic from the specified port number to the specified interface) iptables -A INPUT -i lo -j ACCEPT (allow loopback access to the system)

 

note: Firewalld and iptables can’t be used at the same time on same server — you must choose one.

13. UFW (Uncomplicated Firewall):

Uncomplicated Firewall (UFW) that manages a Netfilter firewall and is a well-known program and default firewall configuration tool on Debian and Ubuntu Linux distributions. It uses iptables for configuration.

 Check UFW firewall status, type the following command:

$ sudo ufw status

Active and disable the UFW firewall using the following command:

$ sudo ufw enable $ sudo ufw disable

You can get the Gui version, by typing the following command:

$ gufw

For finding more information about a particular program see the manual page:

$ man programs_name

Última postagem

Tag