How-To Geek
How to Work with the Network from the Linux Terminal: 11 Commands You Need to Know

Whether you want to download files, diagnose network problems, manage your network interfaces, or view network statistics, there’s a terminal command for that. This collection contains the tried and true tools and a few newer commands.
You can do most of this from a graphical desktop, although even Linux users that rarely use the terminal often launch one to use ping and other network diagnostic tools.
curl & wget
Use the curl or wget commands to download a file from the Internet without leaving the terminal. If you’re using curl, type curl -O followed by the path to the file. wget users can use wget without any options.. The file will appear in the current directory.
curl -O website.com/file
wget website.com/file


ping
ping sends ECHO_REQUEST packets to the address you specify. It’s a great way to see whether your computer can communicate with the Internet or a specific IP address. Bear in mind that many systems are configured not to respond to pings, however.
Unlike the ping command on Windows, the Linux ping command will keep sending packets until you terminate it. You can specify a finite amount of packets with the -c switch.
ping -c 4 google.com


tracepath & traceroute
The tracepath command is similar to traceroute, but it doesn’t require root privileges. It’s also installed by default on Ubuntu, while traceroute isn’t. tracepath traces the network path to a destination you specify and reports each “hop” along the path. If you’re having network problems or slowness, tracepath can show you where the network is failing or where the slowness is occurring.
tracepath example.com


mtr
The mtr command combines ping and tracepath into a single command. mtr will continue to send packets, showing you the ping time to each “hop.” This will also show you any problems — in this case, we can see that hop 6 is losing over 20% of the packets.
mtr howtogeek.com


Press q or Ctrl-C to quit when you’re done.
host
The host command performs DNS lookups. Give it a domain name and you’ll see the associated IP address. Give it an IP address and you’ll see the associated domain name.
host howtogeek.com
host 208.43.115.82


whois
The whois command will show you a website’s whois records, so you can view more information about who registered and owns a specific website.
whois example.com


ifplugstatus
The ifplugstatus command will tell you whether a cable is plugged into a network interface or not. It isn’t installed by default on Ubuntu. Use the following command to install it:
sudo apt-get install ifplugd
Run the command to see the status of all interfaces or specify a specific interface to view its status.
ifplugstatus
ifplugstatus eth0


“Link beat detected” means the cable is plugged in. You’ll see “unplugged” if it isn’t.
ifconfig
The ifconfig command has a variety of options to configure, tune, and debug your system’s network interfaces. It’s also a quick way to view IP addresses and other network interface information. Type ifconfig to view the status of all currently active network interfaces, including their names. You can also specify an interface’s name to view only information about that interface.
ifconfig
ifconfig eth0


ifdown & ifup
The ifdown and ifup commands are the same thing as running ifconfig up or ifconfig down. Given an interface’s name, they take the interface down or bring it up. This requires root permissions, so you have to use sudo on Ubuntu.
sudo ifdown eth0
sudo ifup eth0


Try this on a Linux desktop system and you’ll probably get an error message. Linux desktops usually use NetworkManager, which manages network interfaces for you. These commands will still work on servers without NetworkManager, though.
If you really need to configure NetworkManager from the command line, use the nmcli command.
dhclient
The dhclient command can release your computer’s IP address and get a new one from your DHCP server. This requires root permissions, so use sudo on Ubuntu. Run dhclient with no options to get a new IP address or use the -r switch to release your current IP address.
sudo dhclient -r
sudo dhclient


netstat
The netstat command can show a lot of different interface statistics, including open sockets and routing tables. Run the netstat command with no options and you’ll see a list of open sockets.


There’s a lot more you can do with this command. For example, use the netstat -p command to view the programs associated with open sockets.


View detailed statistics for all ports with netstat -s.


We’ve also covered commands for managing process and working with files in the past.
Got Feedback? Join the discussion at discuss.howtogeek.com
Comments (12)
Chris Hoffman is a technology writer and all-around computer geek. He's as at home using the Linux terminal as he is digging into the Windows registry. Connect with him on Google+.
- Published 03/19/12




Wow great article! makes want to install ubuntu just to use the commands!
I can admit it – there were a few I’d never used/heard of above. Perhaps your choices cover the commands I’ve been using?
* dig – sorta like hosts or nslookup on steroids.
* sudo iptables -L – every networked system ought to be running a firewall.
* sudo nmap – helps discover and map open ports on subnets, perhaps public ports you don’t intend to have open … like RDP, 3389?
* sudo /etc/init.d/networking restart – sometimes restarting the entire network subsystem is a good idea.
The firewall commands aren’t really networking, but how many of us have been troubled by a firewall rule that we didn’t recall or know was in place? I find it is best just to check those at the beginning of any network troubleshooting session to be certain I understand what may be getting in the way of packets, before I start searching for a bad cable. ;)
There’s another command that might interest people: aria2c. It’s usefull for downloding files and torrents.
“Unlike the ping command on Windows, the Linux ping command will keep sending packets until you terminate it.”
In windows it is -t until it is terminated. Might want to correct the information.
@nirav, I think what they meant was that Windows defaults to 4 consecutive pings, while Linux’s default is continuous. Of course with command line switches such as “-t” in Windows you can make ping continuous or like they have described “-c 4″ in Linux to act like Windows.
Awesome article! Thanks for some really solid commands to work with. Linux dusts win-doze…
Good stuff!
Ping and traceroute are not as reliable as they used to be. Many routers and firewalls out there block the ICMP packets
Grep would be a nice addition to this list.
For example if you are checking the whois for an expire date but dont’ want to scroll through the other junk you can do ‘whois domainname.com | grep -i expire’ and it will show you all the lines with the word expire the -i makes the search case insensitive.
Loaded Ubuntu two days ago (onto windows).
These commands are greek to me.
I’ll learn eventually. Sokay ofar.
Nice stuff.
Nice Article!!
Thanks for giving more information about the How to Work with the Network from the Linux Terminal: 11 Commands You Need to Know.
quality article !!