Linux computers in network

13 Linux Network Configuration and Troubleshooting Commands

Computers are connected in a network to exchange information or resources each other. Two or more computer connected through network media called computer network. There are number of network devices or media are involved to form computer network. Computer loaded with Linux Operating System can also be a part of network whether it is small or large network by its multitasking and multiuser natures. Maintaining of system and network up and running is a task of System / Network Administrator’s job. In this article we are going to review frequently used network configuration and troubleshoot commands in Linux.

Linux Network Configuration and Troubleshooting Commands

1. ifconfig

ifconfig (interface configurator) command is use to initialize an interface, assign IP Address to interface and enable or disable interface on demand. With this command you can view IP Address and Hardware / MAC address assign to interface and also MTU (Maximum transmission unit) size.

ifconfig with interface (eth0) command only shows specific interface details like IP Address, MAC Address etc. with -a options will display all available interface details if it is disable also.

Assigning IP Address and Gateway

Assigning an IP Address and Gateway to interface on the fly. The setting will be removed in case of system reboot.

Enable or Disable Specific Interface

To enable or disable specific Interface, we use example command as follows.

Enable eth0
Disable eth0

Setting MTU Size

By default MTU size is 1500. We can set required MTU size with below command. Replace XXXX with size.

Set Interface in Promiscuous mode

Network interface only received packets belongs to that particular NIC. If you put interface in promiscuous mode it will received all the packets. This is very useful to capture packets and analyze later. For this you may require superuser access.

2. PING Command

PING (Packet INternet Groper) command is the best way to test connectivity between two nodes. Whether it is Local Area Network (LAN) or Wide Area Network (WAN). Ping use ICMP (Internet Control Message Protocol) to communicate to other devices. You can ping host name of ip address using below command.

In Linux ping command keep executing until you interrupt. Ping with -c option exit after N number of request (success or error respond).

3. TRACEROUTE Command

traceroute is a network troubleshooting utility which shows number of hops taken to reach destination also determine packets traveling path. Below we are tracing route to global DNS server IP Address and able to reach destination also shows path of that packet is traveling.

4. NETSTAT Command

Netstat (Network Statistic) command display connection info, routing table information etc. To displays routing table information use option as -r.

For more examples of Netstat Command, please read our earlier article on 20 Netstat Command Examples in Linux.

Читайте также:  Пишет наушники динамики не подключены что делать windows

5. DIG Command

Dig (domain information groper) query DNS related information like A Record, CNAME, MX Record etc. This command mainly use to troubleshoot DNS related query.

For more examples of Dig Command, please read the article on 10 Linux Dig Commands to Query DNS.

6. NSLOOKUP Command

nslookup command also use to find out DNS related query. The following examples shows A Record (IP Address) of tecmint.com.

For more NSLOOKUP Command, read the article on 8 Linux Nslookup Command Examples.

7. ROUTE Command

route command also shows and manipulate ip routing table. To see default routing table in Linux, type the following command.

Adding, deleting routes and default Gateway with following commands.

Route Adding
Route Deleting
Adding default Gateway

8. HOST Command

host command to find name to IP or IP to name in IPv4 or IPv6 and also query DNS records.

Using -t option we can find out DNS Resource Records like CNAME, NS, MX, SOA etc.

9. ARP Command

ARP (Address Resolution Protocol) is useful to view / add the contents of the kernel’s ARP tables. To see default table use the command as.

10. ETHTOOL Command

ethtool is a replacement of mii-tool. It is to view, setting speed and duplex of your Network Interface Card (NIC). You can set duplex permanently in /etc/sysconfig/network-scripts/ifcfg-eth0 with ETHTOOL_OPTS variable.

11. IWCONFIG Command

iwconfig command in Linux is use to configure a wireless network interface. You can see and set the basic Wi-Fi details like SSID channel and encryption. You can refer man page of iwconfig to know more.

12. HOSTNAME Command

hostname is to identify in a network. Execute hostname command to see the hostname of your box. You can set hostname permanently in /etc/sysconfig/network. Need to reboot box once set a proper hostname.

13. GUI tool system-config-network

Type system-config-network in command prompt to configure network setting and you will get nice Graphical User Interface (GUI) which may also use to configure IP Address, Gateway, DNS etc. as shown below image.

Linux GUI Network Configuration Tool

This article can be useful for day to day use of Linux Network administrator in Linux / Unix-like operating system. Kindly share through our comment box if we missed out.

If You Appreciate What We Do Here On TecMint, You Should Consider:

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.

Источник

How to Find What Devices are Connected to Network in Linux

Last updated September 30, 2019 By Abhishek Prakash 60 Comments

Brief: This quick trick shows you how to find devices connected to your local network in Linux.

Wireless networks have always been a desirable target for wannabe hackers. Wireless networks are also more vulnerable to hacking than the wired ones.

Forget hacking, do you ever wonder that someone might be leeching off your hard paid wifi network? Maybe a neighbor who once connected to your network and now uses it as his/her own?

It would be nice to check what devices are on your network. This way you can also see if there are some unwanted devices on your network.

So you might end up thinking, “how do I find what devices are connected to my network”?

Читайте также:  Ноутбук завис при выключении windows

I’ll show you how to do that in this quick tutorial. Not only it’s a good idea from security point of view, it is also a good little exercise if you have interest in networking.

We will use both, command line and GUI, way for finding out what devices are connected to your local network in Linux. The process is very simple and easy to use even for beginners.

A. Using Linux command to find devices on the network

Step 1: Install nmap

nmap is one of the most popular network scanning tool in Linux. Use the following command to install nmap in Ubuntu based Linux distributions:

You can easily install it in other Linux distributions as well. It should be in the official software repository.

Step 2: Get IP range of the network

Now we need to know the IP address range of the network. Use the ifconfig command to find the IP address in Linux. Look for wlan0 if you are using wifi or eth0 if you are using Ethernet.

$ ifconfig
wlan0 Link encap:Ethernet HWaddr 70:f1:a1:c2:f2:e9
inet addr:192.168.1.91 Bcast:192.168.1.255 Mask:255.255.255.0
inet6 addr: fe80::73f1:a1ef:fec2:f2e8/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:2135051 errors:0 dropped:0 overruns:0 frame:0
TX packets:2013773 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:1434994913 (1.4 GB) TX bytes:636207445 (636.2 MB)

The important things are highlighted in bold. As you see my IP is 192.168.1.91 and the subnet mask is 255.255.255.0 which means that the ip address range on my network varies from 192.168.1.0 to 192.168.1.255.

You may also use ip a command to know your IP address in Ubuntu and other Linux distributions.

At the same time, I’ll recommend you to read about basic Linux networking commands for more information.

Step 3: Scan to find devices connected to your network

It is advisable to use root privileges while scanning the network for more accurate information. Use the nmap command in the following way:

$ sudo nmap -sn 192.168.1.0/24
Starting Nmap 5.21 ( http://nmap.org ) at 2012-09-01 21:59 CEST

Nmap scan report for neufbox (192.168.1.1)
Host is up (0.012s latency).
MAC Address: E0:A1:D5:72:5A:5C (Unknown)
Nmap scan report for takshak-bambi (192.168.1.91)
Host is up.
Nmap scan report for android-95b23f67te05e1c8 (192.168.1.93)
Host is up (0.36s latency).

As you can see that there are three devices connected to my network. The router itself, my laptop and my Galaxy S2.

If you are wondering about why I used 24 in the above command, you should know a little about CIDR notation. It basically means that the scanning will be from 192.168.1.0 to 192.168.1.255.

B. Using GUI tool to find devices connected to network

When I first wrote this article, there was no GUI tool for this task. Then I saw a Google+ discussion about a new network monitoring tool being developed for elementary OS. I suggested including a periodic device scan feature in this tool and the developer readily agreed.

So, now we have a GUI tool that does this task. It’s called Nutty. Just run install this app and run it. It will periodically scan for new devices on the network and will notify you if there is a new device.

This application is only available for elementary OS, Ubuntu and hopefully, other Ubuntu based Linux distributions. You can find installation instructions on this detailed article on Nutty.

Oh, you can also log in to your router and see the devices connected to your devices. I let you figure the best way to find devices connected to your network.

Like what you read? Please share it with others.

Источник

How to find all the used IP addresses on a network

In my work there is a lot of computer and I want make a joke. I can close computer over the network but finding IP addresses is hard to me.

Читайте также:  Почему линукс лучше для программирования

How can I easily find all online IP adresses from 192.168.1.aa to 192.168.1.zz?

5 Answers 5

Generally, nmap is quite useful to quickly scan networks.

To install nmap, enter the following command in the terminal:

Once the application is installed, enter the following command:

This will show you which hosts responded to ping requests on the network between 192.168.1.0 and 192.168.1.255.

For older versions of Nmap, use -sP :

For additional references, see the following pages:

It is a very useful tool to learn.

If all the computers in your network are Ubuntu or any other distribution that makes use of avahi-daemon (DNS-SD), you can get a detailed list of them (with hostname and IP address) by doing:

If you want to know all the IP addresses used in your network, you can use arp-scan :

As it is not installed by default, you’ll have to install it with sudo apt-get install arp-scan . arp-scan send ARP packets to the local network and displays the responses received, so it shows even firewalled hosts (that block traffic based on IP packets).

Note to the reader: Original answer has been posted a while ago and at the time of when I was only learning shell scripting. See the revisited version below for a new and improved script that performs much faster.

Original Answer

nmap would be my #1 choice, but what if you don’t have it ? The DIY way would be with a ping script that goes through each possible ip address on the network manually. What we have here is just while loop, where we set last number in the address, make silent single ping to the address, check if the command succeed or not (and if it did succeed,then host is obviously up ), and printf statement. Quick and dirty way, took me about 10 mins to write it, but runtime might be a bit slow,though.

Revisited Answer

I originally posted this answer in August of 2015. Since then I’ve learned a bit more about shell scripting, and I once I saw this script, I thought it would be a good idea to revisit this answer to add a few improvements. Here’s a few ideas:

The script is obviously slow and ping waits for response from the host. By default, ping for two RTT, which can vary depending on how congested is your network , and as far as I understand TCP protocol doubles the wait time each time(at least according to this). So we could force ping to time out with -w 1 flag. Since we have 256 addresses and we assume 1 second for each address, the script will take about 256/60 = 4.27 minutes.

Doing a command and then capturing its exit status with $? wasn’t really necessary. The if . then;. fi can operate on commands directly. In other words, it’s sufficient to do this:

The printf command can be rewritten as so:

This is more of a stylistic change, but it’s consistent with how printf works and looks like in a lot of other languages, with quoting «$NUM» variable. Quoting here isn’t necessary — since we’re dealing with numbers only, we don’t need to anticipate word-splitting due to having spaces in a variable.

Much better performance improvement can be achieved if we spawn several background processes. The script edit below does exactly that. I put the ping and printf into a function, pingf (yes, corny name, I know). Now, there’s also one single main function which does the looping and calling of pingf .

How much better does that work ? Not bad, actually, takes a matter of seconds.

Источник

Оцените статью