Login
Password

Forgot your password?

Managing Interfaces Using Linux Bash

By Edited Oct 25, 2016 0 0

IPConfig

 

ipconfig

ifconfig is an older command in the Linux Terminal networking lineup but one that I still like to use to inspect my interfaces. Typing this command by itself will show me the connections labeled eth0 for my Ethernet line, lo for the loopback address (127.0.0.1), and wlan0 for the link to the wireless LAN, or I can type ifconfig wlan0 if I just want to inspect the settings for my WLAN. Terminal can only work with the interfaces that are connected directly to the machine you're working with but is still one of several useful tools for working with your network.

A similar command is iwconfig, which is useful for taking a look at wireless devices that your computer is connected to. Typing in iwconfig wlan0 tells me that, at the time this article was written, my wlan0 interface was connected to a router called NETGEAR and some details about its specifications and settings.

The IP Command

IP Command

The ip command is designed to take on most of the functionality of the classic ifconfig, route and arp. These three older commands are still widely used by longtime Linux users, probably out of pure habit. The format is typically, ip [options] object [command], where object tells Bash what is to be modified or displayed, such as link for a network device or addr for an IP address.

IP addressing

The ip addr command can be used to show information about specific interfaces, such as ip addr show dev wlan0 for a wireless LAN connection. This command is also useful for setting IP addresses for each interface, such as ip addr add 192.168.1.30 dev wlan0. Then, the next time you view the settings for the interface called wlan0, its IP address should be set to the one you specified.

Routing

route

Simply typing route into Terminal should give you a chart that looks similar to the one above. It provides useful information about the gateway, mask and interface used to send data on the next hop of its journey. Using the route command to determine the next hop should look like, route add -net 192.168.1.1 gw 192.168.1.0. You can use the ip command to do essentially the same thing by typing in ip route add 192.168.1.1 gw 192.168.1.0. This tells packets coming from your computer that they can reach the IP address 192.168.1.1 by using the gateway 192.168.1.0.

ARP

The familiar Address Resolution Protocol (ARP) essentially matches IP addresses with its corresponding MAC address. The arp command was once the usual way to detect devices directly connected to a Linux machine and it still works if you still find yourself typing it in. A newer way to detect your computer's neighbors is to use ip neigh. This tells me that I can reach a device with an IP address of 192.168.1.1 and a MAC address of 00:22:3f:a0:c9:9e through my wlan0 link.

Enabling and Disabling Interfaces

IP link

Under normal circumstances, interfaces should be up and running as much as possible. However, there might be cases where you want to disable a connection for routine maintenance or maybe to slow down an unauthorized user. You can do this just by typing in, ip link set down eth0. Then, once you've taken the appropriate damage-control or maintenance steps, you can bring the link back up by typing ip link set up eth0.

Troubleshooting

Terminal gives you several options for troubleshooting if one of your interfaces seems to have gone down. Ping works, though it will give you an unlimited number of responses unless you either use CTRL+C while Terminal is pinging your destination or limit the number of responses by using the -c option. Another option I use is tracepath xxx.xxx.xxx.xxx, which gives me an idea of exactly where a packet might be dropping out on its way to any given host. Netstat is good for tracking down statistics, connections, and routing information.

 

What's In It For You?

Terminal is Linux's exceedingly powerful answer to Microsoft Windows' less-powerful Command Line and, as such, is a useful tool for managing your Linux box's networking needs. If you are curious about the many options Bash has for your network connections, man ip will tell you everything you ever want to know about this command.

Linux User and Developer

This is one of several go-to magazines for Linux professionals who want to keep up with the rapidly evolving world of Linux and open-source software.

Advertisement
Advertisement

Comments

Add a new comment - No HTML
You must be logged in and verified to post a comment. Please log in or sign up to comment.

Explore InfoBarrel

Auto Business & Money Entertainment Environment Health History Home & Garden InfoBarrel University Lifestyle Sports Technology Travel & Places
© Copyright 2008 - 2016 by Hinzie Media Inc. Terms of Service Privacy Policy XML Sitemap

Follow IB Technology