Movatterモバイル変換


[0]ホーム

URL:


Skip to content
Tecmint: Linux Howtos, Tutorials & Guides

13 Linux Network Configuration and Troubleshooting Commands

Read Time: 7 minsCategoriesLinux Commands,Networking Commands56 Comments

Computers are connected in a network to exchange information or resources with each other. Two or more computers are connected through network media called acomputer network. There is a number of network devices or media are involved to form a computer network.

Computer loaded withLinux Operating System can also be a part of network whether it is a small or large network by itsmultitasking and multiuser natures. Maintaining the system and network up and running is a task of theSystem / Network Administrator’s job.

[ You might also like:22 Linux Networking Commands for Sysadmin ]

In this article, we are going to review frequently used network configuration and troubleshoot commands in Linux.

1. ifconfig Command

ifconfig (interface configurator) command is used to initialize an interface, assignIP Address to interface andenable ordisable interface on demand.

With this command, you can viewIP Address andHardware /MAC address assign to interface and alsoMTU (Maximum transmission unit) size.

# ifconfigeth0      Link encap:EthernetHWaddr 00:0C:29:28:FD:4Cinet addr:192.168.50.2  Bcast:192.168.50.255  Mask:255.255.255.0          inet6 addr: fe80::20c:29ff:fe28:fd4c/64 Scope:Link          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1          RX packets:6093 errors:0 dropped:0 overruns:0 frame:0          TX packets:4824 errors:0 dropped:0 overruns:0 carrier:0          collisions:0 txqueuelen:1000          RX bytes:6125302 (5.8 MiB)  TX bytes:536966 (524.3 KiB)          Interrupt:18 Base address:0x2000lo        Link encap:Local Loopback          inet addr:127.0.0.1  Mask:255.0.0.0          inet6 addr: ::1/128 Scope:Host          UP LOOPBACK RUNNING  MTU:16436  Metric:1          RX packets:8 errors:0 dropped:0 overruns:0 frame:0          TX packets:8 errors:0 dropped:0 overruns:0 carrier:0          collisions:0 txqueuelen:0          RX bytes:480 (480.0 b)  TX bytes:480 (480.0 b)

ifconfig with interface (eth0) command only shows specific interface details likeIP Address,MAC Address, etc. with-a option will display all available interface details if it is disabled also.

# ifconfig eth0eth0      Link encap:Ethernet  HWaddr 00:0C:29:28:FD:4C          inet addr:192.168.50.2  Bcast:192.168.50.255  Mask:255.255.255.0          inet6 addr: fe80::20c:29ff:fe28:fd4c/64 Scope:Link          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1          RX packets:6119 errors:0 dropped:0 overruns:0 frame:0          TX packets:4841 errors:0 dropped:0 overruns:0 carrier:0          collisions:0 txqueuelen:1000          RX bytes:6127464 (5.8 MiB)  TX bytes:539648 (527.0 KiB)          Interrupt:18 Base address:0x2000

Set IP Address and Gateway in Linux

Assigning anIP Address andGateway to the interface on the fly. The setting will be removed in case of a system reboot.

# ifconfig eth0 192.168.50.5 netmask 255.255.255.0

Enable or Disable Specific Interface

Toenable ordisable a specific Interface, we use the example command as follows.

Enable eth0
# ifup eth0
Disable eth0
# ifdown eth0

Setting MTU Size

By defaultMTU size is1500. We can set the requiredMTU size with the below command. ReplaceXXXX with size.

# ifconfig eth0 mtu XXXX

Set Interface in Promiscuous Mode

The network interface only received packets belonging to that particularNIC. If you put the interface in thepromiscuous mode it will receive all the packets. This is very useful to capture packets and analyze them later. For this, you may require superuser access.

# ifconfig eth0 - promisc

Update: Theifconfig command is replaced by theIP command in most modern Linux distributions.

2. Ping Command

Ping (Packet INternet Groper) command is the best way to test connectivity betweentwo nodes. Whether it isLocal Area Network (LAN) orWide Area Network (WAN).

Ping usesICMP (Internet Control Message Protocol) to communicate to other devices. You can ping hostname orip address using the below commands.

# ping 4.2.2.2PING 4.2.2.2 (4.2.2.2) 56(84) bytes of data.64 bytes from 4.2.2.2: icmp_seq=1 ttl=44 time=203 ms64 bytes from 4.2.2.2: icmp_seq=2 ttl=44 time=201 ms64 bytes from 4.2.2.2: icmp_seq=3 ttl=44 time=201 msOR# ping www.tecmint.comPING tecmint.com (50.116.66.136) 56(84) bytes of data.64 bytes from 50.116.66.136: icmp_seq=1 ttl=47 time=284 ms64 bytes from 50.116.66.136: icmp_seq=2 ttl=47 time=287 ms64 bytes from 50.116.66.136: icmp_seq=3 ttl=47 time=285 ms

In theLinux ping command keep executing until you interrupt. Ping with-c option exit afterN number of requests (success or error respond).

# ping -c 5 www.tecmint.comPING tecmint.com (50.116.66.136) 56(84) bytes of data.64 bytes from 50.116.66.136: icmp_seq=1 ttl=47 time=285 ms64 bytes from 50.116.66.136: icmp_seq=2 ttl=47 time=285 ms64 bytes from 50.116.66.136: icmp_seq=3 ttl=47 time=285 ms64 bytes from 50.116.66.136: icmp_seq=4 ttl=47 time=285 ms64 bytes from 50.116.66.136: icmp_seq=5 ttl=47 time=285 ms--- tecmint.com ping statistics ---5 packets transmitted, 5 received, 0% packet loss, time 4295msrtt min/avg/max/mdev = 285.062/285.324/285.406/0.599 ms

3. Traceroute Command

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

# traceroute 4.2.2.2traceroute to 4.2.2.2 (4.2.2.2), 30 hops max, 60 byte packets 1  192.168.50.1 (192.168.50.1)  0.217 ms  0.624 ms  0.133 ms 2  227.18.106.27.mysipl.com (27.106.18.227)  2.343 ms  1.910 ms  1.799 ms 3  221-231-119-111.mysipl.com (111.119.231.221)  4.334 ms  4.001 ms  5.619 ms 4  10.0.0.5 (10.0.0.5)  5.386 ms  6.490 ms  6.224 ms 5  gi0-0-0.dgw1.bom2.pacific.net.in (203.123.129.25)  7.798 ms  7.614 ms  7.378 ms 6  115.113.165.49.static-mumbai.vsnl.net.in (115.113.165.49)  10.852 ms  5.389 ms  4.322 ms 7  ix-0-100.tcore1.MLV-Mumbai.as6453.net (180.87.38.5)  5.836 ms  5.590 ms  5.503 ms 8  if-9-5.tcore1.WYN-Marseille.as6453.net (80.231.217.17)  216.909 ms  198.864 ms  201.737 ms 9  if-2-2.tcore2.WYN-Marseille.as6453.net (80.231.217.2)  203.305 ms  203.141 ms  202.888 ms10  if-5-2.tcore1.WV6-Madrid.as6453.net (80.231.200.6)  200.552 ms  202.463 ms  202.222 ms11  if-8-2.tcore2.SV8-Highbridge.as6453.net (80.231.91.26)  205.446 ms  215.885 ms  202.867 ms12  if-2-2.tcore1.SV8-Highbridge.as6453.net (80.231.139.2)  202.675 ms  201.540 ms  203.972 ms13  if-6-2.tcore1.NJY-Newark.as6453.net (80.231.138.18)  203.732 ms  203.496 ms  202.951 ms14  if-2-2.tcore2.NJY-Newark.as6453.net (66.198.70.2)  203.858 ms  203.373 ms  203.208 ms15  66.198.111.26 (66.198.111.26)  201.093 ms 63.243.128.25 (63.243.128.25)  206.597 ms 66.198.111.26 (66.198.111.26)  204.178 ms16  ae9.edge1.NewYork.Level3.net (4.68.62.185)  205.960 ms  205.740 ms  205.487 ms17  vlan51.ebr1.NewYork2.Level3.net (4.69.138.222)  203.867 ms vlan52.ebr2.NewYork2.Level3.net (4.69.138.254)  202.850 ms vlan51.ebr1.NewYork2.Level3.net (4.69.138.222)  202.351 ms18  ae-6-6.ebr2.NewYork1.Level3.net (4.69.141.21)  201.771 ms  201.185 ms  201.120 ms19  ae-81-81.csw3.NewYork1.Level3.net (4.69.134.74)  202.407 ms  201.479 ms ae-92-92.csw4.NewYork1.Level3.net (4.69.148.46)  208.145 ms20  ae-2-70.edge2.NewYork1.Level3.net (4.69.155.80)  200.572 ms ae-4-90.edge2.NewYork1.Level3.net (4.69.155.208)  200.402 ms ae-1-60.edge2.NewYork1.Level3.net (4.69.155.16)  203.573 ms21  b.resolvers.Level3.net (4.2.2.2)  199.725 ms  199.190 ms  202.488 ms

4. Netstat Command

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

# netstat -rKernel IP routing tableDestination     Gateway         Genmask         Flags   MSS Window  irtt Iface192.168.50.0    *               255.255.255.0   U         0 0          0 eth0link-local      *               255.255.0.0     U         0 0          0 eth0default         192.168.50.1    0.0.0.0         UG        0 0          0 eth0

For more examples ofNetstat Command, please read our earlier article on20 Netstat Command Examples in Linux.

Update: Thenetstat command is replaced by thess (socket statistics) command in most modern Linux distributions.

5. Dig Command

Dig (domain information groper) queryDNS related information likeA Record,CNAME,MX Record, etc. This command is mainly used to troubleshootDNS-related queries.

# dig www.tecmint.com; <<>> DiG 9.8.2rc1-RedHat-9.8.2-0.10.rc1.el6 <<>> www.tecmint.com;; global options: +cmd;; Got answer:;; ->>HEADER<

For more examples ofDig Command, please read the article on10 Linux Dig Commands to Query DNS.

6. Nslookup Command

nslookup command is also used to find outDNS-related queries. The following examples showA Record (IP Address) oftecmint.com.

# nslookup www.tecmint.comServer:         4.2.2.2Address:        4.2.2.2#53Non-authoritative answer:www.tecmint.com canonical name = tecmint.com.Name:   tecmint.comAddress: 50.116.66.136

For moreNslookup Command, read the article on8 Linux Nslookup Command Examples.

7. Route Command

route command also shows and manipulates theip routing table. To see the default routing table inLinux, type the following command.

# routeKernel IP routing tableDestination     Gateway         Genmask         Flags Metric Ref    Use Iface192.168.50.0    *               255.255.255.0   U     0      0        0 eth0link-local      *               255.255.0.0     U     1002   0        0 eth0default         192.168.50.1    0.0.0.0         UG    0      0        0 eth0

Adding, deleting routes and default Gateway with following commands.

Add Route in Linux
# route add -net 10.10.10.0/24 gw 192.168.0.1
Delete Route in Linux
# route del -net 10.10.10.0/24 gw 192.168.0.1
Add Default Gateway in Linux
# route add default gw 192.168.0.1

8. Host Command

host command to find a name toIP orIP to name inIPv4 orIPv6 and also queryDNS records.

# host www.google.comwww.google.com has address 173.194.38.180www.google.com has address 173.194.38.176www.google.com has address 173.194.38.177www.google.com has address 173.194.38.178www.google.com has address 173.194.38.179www.google.com has IPv6 address 2404:6800:4003:802::1014

Using-t an option to find out DNS Resource Records likeCNAME,NS,MX,SOA, etc.

# host -t CNAME www.redhat.comwww.redhat.com is an alias for wildcard.redhat.com.edgekey.net.

9. Arp Command

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

# arp -eAddress                  HWtype  HWaddress           Flags Mask            Iface192.168.50.1             ether   00:50:56:c0:00:08   C                     eth0

10. Ethtool Command

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

# ethtool eth0Settings for eth0:        Current message level: 0x00000007 (7)        Link detected: yes

11. Iwconfig Command

iwconfig command inLinux is used to configure awireless network interface. You can see and set the basicWi-Fi details likeSSID channel and encryption. You can refer man page ofiwconfig to know more.

# iwconfig [interface]

12. Hostname Command

Thehostname is to identify in a network. Execute thehostname 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.

# hostname tecmint.com

13. Nmcli and Nmtui Tools

TheNmcli andNmtui tools are used to configure network settings and also used to manage network devices, create, modify, activate/deactivate, and delete network connections in Linux systems.

# nmcli# nmtui
Nmtui Network Manager
Nmtui Network Manager

This article can be useful for day to day use ofLinux Network administrators inLinux / Unix-like operating systems. Kindly share through our comment box if we missed out.

💡Want to Level Up Your Linux Skills?

Check outPro.Tecmint.com forad-free reading,exclusive guides,downloadable resources, andcertification prep (RHCSA, RHCE, LFCS) - all with lifetime access.

Photo of author
Ravi Saive
I'm Ravi Saive, an award-winning entrepreneur and founder of several successful 5-figure online businesses, including TecMint.com, GeeksMint.com, UbuntuMint.com, and the premium learning hub Pro.Tecmint.com.

Each tutorial atTecMint is created by a team of experienced Linux system administrators so that it meets our high-quality standards.

Join theTecMint Weekly Newsletter (More Than156,129 Linux Enthusiasts Have Subscribed)
Was this article helpful? Pleaseadd a comment orbuy me a coffee to show your appreciation.

Related Posts

56 Comments

Leave a Reply
  1. Why does the Tecmint staff insist on prefixing all their sample command in all their articles with a hash mark(#)? Commands written in this way will be treated as comments by the Linux Operating System and never be executed.

    Reply
    • @Dragonmouth,

      Thank you for your comment. The Tecmint staff may prefix sample commands with a hash mark(#) to indicate that they are meant to be run as root or with elevated privileges. This is a common convention in Linux documentation and tutorials.

      Reply
  2. Hi,

    Thanks a lot, very useful article.

    Reply
  3. dns is replying fine but internet is not working in Ubuntu.

    Reply
    • Easy fix, is your ping responding? if not check with the command “route -n” and make sure your gateways are lining up. If not type the command (With your IP address of your router, my example is the basic 192.168.1.1… “route add default gw 192.168.1.1” Then check the internet once again.

      Reply
  4. system-config-network doesn’t work on my KDE Neon

    Reply
  5. This article is so out of date that it should be removed. In particular, use the ip command and use tracepath, not traceroute.

    Reply
    • It is a bit out of date, sure, but these commands still work.traceroute is still usable, and pathping is ICMP, it is not the same underlying protocol as traceroute. It’s always easy to criticize. The author might not be an authoritative person for Linux administration, maybe just someone sharing their thoughts

      Reply
  6. Excellent list, all commands are very useful.

    Reply
  7. some command not working on kali

    Reply
  8. give me full command list bro

    Reply
  9. I need information about “Write a short note on troubleshooting in Linux”

    Reply
  10. I have interview in linux I am fresher they ask me to prepare network commands.
    Is this enough for that as you taught above!!!

    Reply
  11. What would you recommend for a Certified Linux technician, with no experience on Linux OS. I would like to get more experience on useful commands and how to navigate in and out through network settings for servers.

    Reply
  12. This is very very usefull

    Reply
  13. very useful

    Reply
  14. this is very usefull ,thanx

    Reply
  15. I would add tcpdump and wire shark for sniffing packets
    Traceroute is good as well

    Reply
  16. Kernel bypass networking is increasing reputation. This depicts affecting organize of Ethernet hardware straight into user space procedures to evade the transparency of con-terminal with the operating system Kernel.

    Reply
  17. Are those tools used for system configuration?

    Reply
  18. overall the content is good

    Reply
  19. will u please give the clear information regarding the nslookup command in linux

    Reply
  20. Thanks for the comprehensive definitions and examples.

    Reply
  21. Hi

    if I set up a VPN to a server using Windows, I am able to ping to the server (192.168.1.1) AND to a desktop in the server network (i.e. 192.168.1.221). When I do the same under Linux I can ping to the server, but not anymore to the desktop linked to the server (i.e. 192.168.1.221).

    Any suggestion what tool I could use to discover the problem?

    Gert

    Reply
  22. if i use ndis wrapper to install my wireless driver in Centos 6.5 an i can’t find a record which identify my wireless driver and i can’t find a record in /etc/sysconfig/network-scripts which show me lo and eth0 only !!!!!!!!

    Reply
  23. i want to know what is the command for inseting data into existing file in anyware instead of vi editor

    pls let me know

    Reply
  24. which is the program that contains the package “system-config-network” ??

    Reply
  25. what is the command in Linux to find traffic between to IPS … i.e Source IP and Destination IP

    Reply
  26. I believe ping is the “packet internet groper”, not “gopher” as indicated

    Reply
  27. we are not able to ping the gateway ip. how can i check this. can you please advice me.

    Reply
  28. p.s.

    I love Linux but I’m kind of unskilled/beginner
    I did fix a few bugs though :))

    Reply
  29. Hello,

    Do you happen to know how to delete my router details on linux and start again? As in a way that the router could not recognize my device unless I manually take care of that.
    We’re having kind of network issues because the router is “confused” because it doesn’t know which Ip address to go to since it has been configurated since the very beginning on two laptops while it actually is alloud on one. SOrry for my bad English. Looking forward for your reply.
    Thanks!

    Adelina

    Reply
  30. over all information is good

    Reply
  31. Could you also go through some commands which show hardware and driver details?

    Reply
  32. Hey… can we down the interface using “system-config-network” command?
    If yes how?

    Reply
  33. ifconfig is mostly depricated

    ip command is the replacement

    Reply
  34. ifconfig, route, and netstat are deprecated so you might want to rewrite your howto substituting ip and ss

    Reply
  35. Sorry, but according to this posthttps://dougvitale.wordpress.com/2011/12/21/deprecated-linux-networking-commands-and-their-replacements/ many of the commands you’ve listed here are deprecated.

    Reply
  36. Hasn’t ifconfig been deprecated and replaced by the ip command?

    Reply
  37. Informative article, Thank you.

    Reply

Got Something to Say? Join the Discussion...Cancel reply

Thank you for taking the time to share your thoughts with us. We appreciate your decision to leave a comment and value your contribution to the discussion. It's important to note that we moderate all comments in accordance with ourcomment policy to ensure a respectful and constructive conversation.

Rest assured that your email address will remain private and will not be published or shared with anyone. We prioritize the privacy and security of our users.

Upgrade Your Linux Learning with Pro.Tecmint

If you find TecMint helpful, consider supporting us by subscribing toPro.Tecmint.com – our premium platform with exclusive guides, ad-free experience, early access to tutorials, and much more.

Your support helps us keep creating quality Linux content for everyone.

Linux Commands and Tools

Linux Server Monitoring Tools

Learn Linux Tricks & Tips

Best Linux Tools


[8]ページ先頭

©2009-2025 Movatter.jp