|
Home | Switchboard | Unix Administration | Red Hat | TCP/IP Networks | Neoliberalism | Toxic Managers |
(slightly skeptical) Educational society promoting "Back to basics" movement against IT overcomplexity and bastardization of classic Unix |
News | See Also | Recommended Links | Reference | ping | hostname |
Linux route command | Traceroute | Tcpdump | netstat | host | |
ethtool | ip command | Netcat | Nmap | Humor | Etc |
|
The "if" in ifconfig, and also in ifup, ifdown, and ifstatus, is an abbreviation of "interface". This command is located in the /usr/sbin directory. The ifconfig command commonly used to display information about the configuration of the network interface specified:
|
ifconfig eth01
To examine the status of all network interfaces, type:
ifconfig -a
If used by the superuser, the ifconfig command can configure all network interface parameters. The ifconfig command can also be used to redefine an interface's IP address or parameters.
Status flags indicate state of the interface as follows:
ifconfig eth0 upcauses eth0 to be activated.
ifconfig eth0 downcauses eth0 to be deactivated if it is currently active.
ifconfig eth0 netmask 255.255.255.0
ifconfig eth0 192.168.2.103
will set that interface's IP address. You can also specify network mask without keyword netmask by using "slash" notation, for example
ifconfig eth0 192.168.2.103/24
To set IP IP address and network mask: /sbin/ifconfig -a eth0 192.168.1.5 netmask 255.255.255.0
Verify the settings with /sbin/ifconfig eth0
.
Add the default gateway: /sbin/route add default gw 192.168.1.254
Verify the gateway setting: /sbin/route
. The line beginning with default
should have your gateway under the gateway
column.
Alternately, you can edit the file /etc/sysconfig/network-scripts/ifcfg-eth0
to look
like (replace with your network numbers)
DEVICE=eth0
USERCTL=no
ONBOOT=yes
BOOTPROTO=none
BROADCAST=192.168.1.255
NETWORK=192.168.1.0
NETMASK=255.255.255.0
IPADDR=192.168.1.5
and the file /etc/sysconfig/network
to look like (replace with your network numbers
and hostname)
NETWORKING=yes HOSTNAME=name.host.net FORWARD_IPV4=yes GATEWAYDEV= GATEWAY=192.168.1.254
Generally if you have single default gateway you should define it and hostname in /etc/sysconfig/network
file:
NETWORKING=yes
HOSTNAME=yourhost
GATEWAY=192.168.1.254
Alternative place to define default gateway is /etc/sysconfig/network/route See Linux route command for more details.
As you can see there are three places to define default gateway in Red Hat and the whole thing looks like ad hoc design.
To make changes you made in files active you need to restart networking:
/etc/init.d/network restart
You also need to define DNS in /etc/resolv.conf file
Ping the gateway and a few other computers on the network to verify your settings are correct before and after the reboot.
A couple of commands are used to configure the network interfaces and initialize the routing table. These tasks are usually performed from the network initialization script each time you boot the system. The basic tools for this process are called ifconfig (where "if" stands for interface) and route.
ifconfig is used to make an interface accessible to the kernel networking layer. This involves the assignment of an IP address and other parameters, and activation of the interface, also known as "bringing up" the interface. Being active here means that the kernel will send and receive IP datagrams through the interface. The simplest way to invoke it is with:
ifconfig interface ip-address
This command assigns ip-address to interface and activates it. All other parameters are set to default values. For instance, the default network mask is derived from the network class of the IP address, such as 255.255.0.0 for a class B address. ifconfig is described in detail in the section "All About ifconfig".
To configure speed of the the interface one can use ethtool. It also provide important information about the interface such as speed
# ethtool eth0 Settings for eth0: Supported ports: [ TP ] Supported link modes: 10baseT/Half 10baseT/Full 100baseT/Half 100baseT/Full 1000baseT/Full Supports auto-negotiation: Yes Advertised link modes: 10baseT/Half 10baseT/Full 100baseT/Half 100baseT/Full 1000baseT/Full Advertised auto-negotiation: Yes Speed: 1000Mb/s Duplex: Full Port: Twisted Pair PHYAD: 1 Transceiver: internal Auto-negotiation: on Supports Wake-on: g Wake-on: g Link detected: yesHere full duplex, half duplex and auto-negotiation have the following meanings.
The very first interface to be activated is the loopback interface. You need to be root
ifconfig lo 127.0.0.1
Occasionally, you will see the dummy hostname localhost being used instead of the IP address. ifconfig will look up the name in the hosts file, where an entry should declare it as the hostname for 127.0.0.1:
# Sample /etc/hosts entry for localhost localhost 127.0.0.1
To view the configuration of an interface, you invoke ifconfig, giving it only the interface name as argument:
$ifconfig lo
lo Link encap:Local Loopback inet addr:127.0.0.1 Mask:255.0.0.0 UP LOOPBACK RUNNING MTU:3924 Metric:1 RX packets:0 errors:0 dropped:0 overruns:0 frame:0 TX packets:0 errors:0 dropped:0 overruns:0 carrier:0 Collisions:0
As you can see, the loopback interface has been assigned a netmask of 255.0.0.0, since 127.0.0.1 is a class A address.
Now you can almost start playing with your mini-network. What is still missing is an entry in the routing table that tells IP that it may use this interface as a route to destination 127.0.0.1. This is accomplished by using:
# route add 127.0.0.1
Again, you can use the name localhost instead of the IP address 127.0.0.1, if it is defined in /etc/hosts.
Next, you should check that everything works fine, for example by using ping.
#ping localhost
PING localhost (127.0.0.1): 56 data bytes 64 bytes from 127.0.0.1: icmp_seq=0 ttl=255 time=0.4 ms 64 bytes from 127.0.0.1: icmp_seq=1 ttl=255 time=0.4 ms 64 bytes from 127.0.0.1: icmp_seq=2 ttl=255 time=0.4 ms ^C --- localhost ping statistics --- 3 packets transmitted, 3 packets received, 0% packet loss round-trip min/avg/max = 0.4/0.4/0.4 ms #
When you invoke ping as shown here, it will continue emitting packets forever, unless
interrupted by the user. The ^C
marks the place where we pressed Ctrl-C.
The previous example shows that packets for 127.0.0.1 are properly delivered and a reply is returned to ping almost instantaneously. This shows that you have successfully set up your first network interface.
If the output you get from ping does not resemble that shown in the previous example, you are in trouble. Check any errors if they indicate that some file hasn't been installed properly. Check that the ifconfig and route binaries you use are compatible with the kernel release you run, and above all, that the kernel has been compiled with networking enabled (you see this from the presence of the /proc/net directory). If you get an error message saying "Network unreachable," you probably got the route command wrong. Make sure you use the same address you gave to ifconfig.
The steps previously described are enough to use networking applications on a standalone host. After
adding the lines mentioned earlier to your network initialization script and making sure it will be
executed at boot time, you may reboot your machine and try out various applications. For instance,
telnet localhost should establish a telnet connection to your host, giving
you a login:
prompt.
However, the loopback interface is useful not only as an example in networking books, or as a test bed during development, but is actually used by some applications during normal operation. Therefore, you always have to configure it, regardless of whether your machine is attached to a network or not: all applications based on RPC use the loopback interface to register themselves with the portmapper daemon at startup. These applications include NIS and NFS.
Configuring an Ethernet interface is pretty much the same as the loopback interface; it just requires a few more parameters when you are using subnetting.
Let's assume that we have subnetted the IP network, which was originally a class B network, into class C subnetworks. To make the interface recognize this, the ifconfig incantation would look like this:
ifconfig eth0 10.192.163.106 netmask 255.255.255.0
This command assigns the eth0 interface the IP address 10.192.163.106. If we omitted the netmask, ifconfig would deduce the netmask from the IP network class, which can result in an incorrect netmask.
To check the results type
eth1 Link encap:Ethernet HWaddr 00:18:8B:49:8F:78 inet addr:10.192.163.106 Bcast:10.192.163.127 Mask:255.255.255.0 UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:11973 errors:0 dropped:0 overruns:0 frame:0 TX packets:4883 errors:13 dropped:0 overruns:0 carrier:13 collisions:13 txqueuelen:1000 RX bytes:966692 (944.0 KiB) TX bytes:1019655 (995.7 KiB) Interrupt:16 Memory:f4000000-f4012800 lo Link encap:Local Loopback inet addr:127.0.0.1 Mask:255.0.0.0 UP LOOPBACK RUNNING MTU:16436 Metric:1 RX packets:5642 errors:0 dropped:0 overruns:0 frame:0 TX packets:5642 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:4658535 (4.4 MiB) TX bytes:4658535 (4.4 MiB)
You can see that ifconfig automatically sets the broadcast address (the Bcast field) to the usual value, which is the host's network number with all the host bits set. Also, the maximum transmission unit (the maximum size of IP datagrams the kernel will generate for this interface) has been set to the maximum size of Ethernet packets: 1,500 bytes. The defaults are usually what you will use, but all these values can be modified if required.
Typically hosts on the network are connected via routers (gateways). For example in a home network router can provide a link to the Internet. In order to use a gateway, you have to provide additional routing information to the networking layer. To defult default gateway you need to type route command. For example
#route add default gw 10.192.163.1
The network name default is a shorthand for 0.0.0.0, which denotes the default route. The default route matches every destination and will be used if there is no more specific route that matches. You do not have to add this name to /etc/networks because it is built into route.
|
Switchboard | ||||
Latest | |||||
Past week | |||||
Past month |
... ... ...
Changing the MTU size with ifconfig command
In order to change the MTU size, use /sbin/ifconfig command as follows:
ifconfig ${Interface} mtu ${SIZE} up ifconfig eth1 mtu 9000 upNote this will only work if supported by both the network interface card and the network components such as switch.
Changing the MTU size permanently under CentOS / RHEL / Fedora Linux
Edit /etc/sysconfig/network-scripts/ifcfg-eth0, enter
# vi /etc/sysconfig/network-scripts/ifcfg-eth0
Add MTU, settings:
MTU="9000"
Save and close the file. Restart networking:
# service network restart
... ... ...
Occasionally, you find yourself without a working network. This article is designed to guide you through the basic steps to work out what is wrong. Hopefully, from there you will be able to find out how to resolve your problem.Note
This guide was written based on an Ubuntu setup, using commands that are installed by default. It should apply to any system that has iproute and mtr installed. The article also assumes you are only dealing with a wired connection. It will mostly apply to a wireless network, but there may be additional steps you need to investigate.
Hardware
The first thing to do is check that your network card has been detected.
Run "ip link"
% ip link 1: lo: <LOOPBACK,UP,10000> mtu 16436 qdisc noqueue link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 2: eth0: <BROADCAST,MULTICAST,UP,10000> mtu 1500 qdisc pfifo_fast qlen 1000 link/ether 00:a0:c9:92:9c:c0 brd ff:ff:ff:ff:ff:ff 3: sit0: <NOARP> mtu 1480 qdisc noop link/sit 0.0.0.0 brd 0.0.0.0You should see eth0. If this is the case, then your network card was detected correctly.
Lets make sure we have a cable plugged in correctly by checking the link status using mii-tool.
% sudo mii-tool eth0: negotiated 100baseTx-FD flow-control, link okIf you see "link ok" then you have a working ethernet connection. If you don't you should check your network cable is plugged in securely and that it is wired correctly and your switch is working correctly.
IP networking
The next thing to do is to check that you have got an IP address for that network device. You can do that by running "ip addr show dev eth0"
2: eth0: <BROADCAST,MULTICAST,UP,10000> mtu 1500 qdisc pfifo_fast qlen 1000 link/ether 00:a0:c9:92:9c:c0 brd ff:ff:ff:ff:ff:ff inet 10.187.182.233/27 brd 10.187.182.255 scope global eth0 inet6 2002:8b0:ed:2:2a0:c9ff:fe92:9cc0/64 scope global dynamic valid_lft 2591991sec preferred_lft 604791sec inet6 fe80::2a0:c9ff:fe92:9cc0/64 scope link valid_lft forever preferred_lft foreverThe line you're interested in here is the line that starts inet. If you don't or it starts 169.254 then you don't have an ip address assigned.
You can either get this dynamically via something called DHCP, or you can configure it statically. We'll try dhcp first by running "sudo dhclient eth0"
% sudo dhclient eth0 Password: Internet Systems Consortium DHCP Client V3.0.4 Copyright 2004-2006 Internet Systems Consortium. All rights reserved. For info, please visit http://www.isc.org/sw/dhcp/ Listening on LPF/eth0/00:a0:c9:92:9c:c0 Sending on LPF/eth0/00:a0:c9:92:9c:c0 Sending on Socket/fallback DHCPDISCOVER on eth0 to 255.255.255.255 port 67 interval 4 DHCPOFFER from 10.187.182.226 DHCPREQUEST on eth0 to 255.255.255.255 port 67 DHCPACK from 10.187.182.226 bound to 10.187.182.233 -- renewal in 38436 seconds.If you keep seeing DHCPDISCOVER lines over and over, then it means your router is not providing addresses via DHCP, although I find this quite unlikely.
If you repeat the "ip addr show eth0" line again you should see that you now have a new "inet" line.
Lets see if our networking is working. Let's ping the machine that gave us an IP address. If you take the IP address from the DHCPOFFER line and try to ping it using "ping <ipaddress>". Press Ctrl-C to stop it.
% ping 10.187.182.226 PING 10.187.182.226 (10.187.182.226) 56(84) bytes of data. 64 bytes from 10.187.182.226: icmp_seq=1 ttl=64 time=0.364 ms 64 bytes from 10.187.182.226: icmp_seq=2 ttl=64 time=0.274 ms 64 bytes from 10.187.182.226: icmp_seq=3 ttl=64 time=0.286 ms --- 10.187.182.226 ping statistics --- 3 packets transmitted, 3 received, 0% packet loss, time 2006ms rtt min/avg/max/mdev = 0.274/0.308/0.364/0.039 msIf you get lines like this, then you have working IP networking.
So we've been given an IP address from somewhere. Let's see if they have given us a default route. We can do this by running "ip route"
% ip route 10.187.182.224/27 dev eth0 proto kernel scope link src 10.187.182.233 default via 10.187.182.225 dev eth0From this we can see that our default route is to 10.187.182.225 using eth0 network device. Lets try pinging that:
% ping 10.187.182.225 PING 10.187.182.225 (10.187.182.225) 56(84) bytes of data. 64 bytes from 10.187.182.225: icmp_seq=1 ttl=64 time=0.317 ms 64 bytes from 10.187.182.225: icmp_seq=2 ttl=64 time=0.291 ms 64 bytes from 10.187.182.225: icmp_seq=3 ttl=64 time=0.224 ms --- 81.187.182.226 ping statistics --- 3 packets transmitted, 3 received, 0% packet loss, time 2001ms rtt min/avg/max/mdev = 0.224/0.277/0.317/0.041 msSo we know we can at least reach the router.
Now, lets see if we can get any further than this. Lets try pinging Ubuntu's webserver.
% ping 82.211.81.166 PING 82.211.81.166 (82.211.81.166) 56(84) bytes of data. 64 bytes from 82.211.81.166: icmp_seq=1 ttl=52 time=30.5 ms 64 bytes from 82.211.81.166: icmp_seq=2 ttl=52 time=30.8 ms 64 bytes from 82.211.81.166: icmp_seq=3 ttl=52 time=30.2 ms --- 82.211.81.166 ping statistics --- 3 packets transmitted, 3 received, 0% packet loss, time 2006ms rtt min/avg/max/mdev = 30.232/30.532/30.836/0.318 msIf this works, then we have working networking and can move on to checking DNS.
If this doesn't work, we need to find out where the problem lies using mtr (I'd normally suggest traceroute here, but it doesn't look like it's a part of the standard Ubuntu install). We will trace the route to ubuntu's webserver again.
% mtr -r -c 1 82.211.81.166 HOST: mojo-jojo Loss% Snt Last Avg Best Wrst StDev 1. brian.catnip.org.uk 0.0% 1 0.4 0.4 0.4 0.4 0.0 2. 10.187.182.201 0.0% 1 1.1 1.1 1.1 1.1 0.0 3. careless.aaisp.net.uk 0.0% 1 30.2 30.2 30.2 30.2 0.0 4. needless.aaisp.net.uk 0.0% 1 28.7 28.7 28.7 28.7 0.0 5. ge-2-0-216.ipcolo2.London1.L 0.0% 1 30.2 30.2 30.2 30.2 0.0 6. ae-0-55.bbr1.London1.Level3. 0.0% 1 30.2 30.2 30.2 30.2 0.0 7. as-0-0.bbr2.London2.Level3.n 0.0% 1 30.3 30.3 30.3 30.3 0.0 8. ge-3-0-0-55.gar1.London2.Lev 0.0% 1 30.2 30.2 30.2 30.2 0.0 9. 195.50.91.146 0.0% 1 30.4 30.4 30.4 30.4 0.0 10. vlan102.core-l-1.lon2.mnet.n 0.0% 1 29.6 29.6 29.6 29.6 0.0 11. 85.133.32.130 0.0% 1 31.7 31.7 31.7 31.7 0.0 12. 82.211.81.76 0.0% 1 30.0 30.0 30.0 30.0 0.0 13. signey.ubuntu.com 0.0% 1 29.9 29.9 29.9 29.9 0.0This shows us every router between us and the remote machine. The first line will show your ADSL router. The line after that will be the remote end of your ADSL line. If your adsl is not connected you won't be able to reach the second hop. Anything beyond this is nothing you can control, but considering it works in Windows it's unlikely that this is the case.
There is another possibility why you can't reach the second hop and that is that the default route isn't correct, but this address should have been given to you via DHCP like your IP address.
If this is all working, we can check DNS.
Try looking up a host by name using the host command:
% host www.ubuntu.com www.ubuntu.com has address 82.211.81.166If this works, then your networking should be working fine. If not, then we need to check /etc/resolv.conf. It should look something like:
% cat /etc/resolv.conf nameserver 10.187.182.226 nameserver 10.187.182.229Here we list DNS name servers. You should edit this file to use the name servers that you were given by your ISP.
Further Reading
- Linux Network Administrator's Guide by Terry Dawson, Gregor N Purdy, Tony Bautts
- Linux Networking Clearly Explained by Bryan Pfaffenberger, Michael Jang
- Linux Home Networking - Troubleshooting
- Linux Network Administrator's Guide - Online
ifconfig - Wikipedia, the free encyclopedia
Other networking utilities of note include:
See the manpages for any of these utilities to get more information by entering "man utilityname" at the command line. For instance, the manpage for the arp utility is accessed by entering man arp. You can get more information about the man utility by entering man man.
Society
Groupthink : Two Party System as Polyarchy : Corruption of Regulators : Bureaucracies : Understanding Micromanagers and Control Freaks : Toxic Managers : Harvard Mafia : Diplomatic Communication : Surviving a Bad Performance Review : Insufficient Retirement Funds as Immanent Problem of Neoliberal Regime : PseudoScience : Who Rules America : Neoliberalism : The Iron Law of Oligarchy : Libertarian Philosophy
Quotes
War and Peace : Skeptical Finance : John Kenneth Galbraith :Talleyrand : Oscar Wilde : Otto Von Bismarck : Keynes : George Carlin : Skeptics : Propaganda : SE quotes : Language Design and Programming Quotes : Random IT-related quotes : Somerset Maugham : Marcus Aurelius : Kurt Vonnegut : Eric Hoffer : Winston Churchill : Napoleon Bonaparte : Ambrose Bierce : Bernard Shaw : Mark Twain Quotes
Bulletin:
Vol 25, No.12 (December, 2013) Rational Fools vs. Efficient Crooks The efficient markets hypothesis : Political Skeptic Bulletin, 2013 : Unemployment Bulletin, 2010 : Vol 23, No.10 (October, 2011) An observation about corporate security departments : Slightly Skeptical Euromaydan Chronicles, June 2014 : Greenspan legacy bulletin, 2008 : Vol 25, No.10 (October, 2013) Cryptolocker Trojan (Win32/Crilock.A) : Vol 25, No.08 (August, 2013) Cloud providers as intelligence collection hubs : Financial Humor Bulletin, 2010 : Inequality Bulletin, 2009 : Financial Humor Bulletin, 2008 : Copyleft Problems Bulletin, 2004 : Financial Humor Bulletin, 2011 : Energy Bulletin, 2010 : Malware Protection Bulletin, 2010 : Vol 26, No.1 (January, 2013) Object-Oriented Cult : Political Skeptic Bulletin, 2011 : Vol 23, No.11 (November, 2011) Softpanorama classification of sysadmin horror stories : Vol 25, No.05 (May, 2013) Corporate bullshit as a communication method : Vol 25, No.06 (June, 2013) A Note on the Relationship of Brooks Law and Conway Law
History:
Fifty glorious years (1950-2000): the triumph of the US computer engineering : Donald Knuth : TAoCP and its Influence of Computer Science : Richard Stallman : Linus Torvalds : Larry Wall : John K. Ousterhout : CTSS : Multix OS Unix History : Unix shell history : VI editor : History of pipes concept : Solaris : MS DOS : Programming Languages History : PL/1 : Simula 67 : C : History of GCC development : Scripting Languages : Perl history : OS History : Mail : DNS : SSH : CPU Instruction Sets : SPARC systems 1987-2006 : Norton Commander : Norton Utilities : Norton Ghost : Frontpage history : Malware Defense History : GNU Screen : OSS early history
Classic books:
The Peter Principle : Parkinson Law : 1984 : The Mythical Man-Month : How to Solve It by George Polya : The Art of Computer Programming : The Elements of Programming Style : The Unix Hater’s Handbook : The Jargon file : The True Believer : Programming Pearls : The Good Soldier Svejk : The Power Elite
Most popular humor pages:
Manifest of the Softpanorama IT Slacker Society : Ten Commandments of the IT Slackers Society : Computer Humor Collection : BSD Logo Story : The Cuckoo's Egg : IT Slang : C++ Humor : ARE YOU A BBS ADDICT? : The Perl Purity Test : Object oriented programmers of all nations : Financial Humor : Financial Humor Bulletin, 2008 : Financial Humor Bulletin, 2010 : The Most Comprehensive Collection of Editor-related Humor : Programming Language Humor : Goldman Sachs related humor : Greenspan humor : C Humor : Scripting Humor : Real Programmers Humor : Web Humor : GPL-related Humor : OFM Humor : Politically Incorrect Humor : IDS Humor : "Linux Sucks" Humor : Russian Musical Humor : Best Russian Programmer Humor : Microsoft plans to buy Catholic Church : Richard Stallman Related Humor : Admin Humor : Perl-related Humor : Linus Torvalds Related humor : PseudoScience Related Humor : Networking Humor : Shell Humor : Financial Humor Bulletin, 2011 : Financial Humor Bulletin, 2012 : Financial Humor Bulletin, 2013 : Java Humor : Software Engineering Humor : Sun Solaris Related Humor : Education Humor : IBM Humor : Assembler-related Humor : VIM Humor : Computer Viruses Humor : Bright tomorrow is rescheduled to a day after tomorrow : Classic Computer Humor
The Last but not Least Technology is dominated by two types of people: those who understand what they do not manage and those who manage what they do not understand ~Archibald Putt. Ph.D
Copyright © 1996-2021 by Softpanorama Society. www.softpanorama.org was initially created as a service to the (now defunct) UN Sustainable Development Networking Programme (SDNP) without any remuneration. This document is an industrial compilation designed and created exclusively for educational use and is distributed under the Softpanorama Content License. Original materials copyright belong to respective owners. Quotes are made for educational purposes only in compliance with the fair use doctrine.
FAIR USE NOTICE This site contains copyrighted material the use of which has not always been specifically authorized by the copyright owner. We are making such material available to advance understanding of computer science, IT technology, economic, scientific, and social issues. We believe this constitutes a 'fair use' of any such copyrighted material as provided by section 107 of the US Copyright Law according to which such material can be distributed without profit exclusively for research and educational purposes.
This is a Spartan WHYFF (We Help You For Free) site written by people for whom English is not a native language. Grammar and spelling errors should be expected. The site contain some broken links as it develops like a living tree...
|
You can use PayPal to to buy a cup of coffee for authors of this site |
Disclaimer:
The statements, views and opinions presented on this web page are those of the author (or referenced source) and are not endorsed by, nor do they necessarily reflect, the opinions of the Softpanorama society. We do not warrant the correctness of the information provided or its fitness for any purpose. The site uses AdSense so you need to be aware of Google privacy policy. You you do not want to be tracked by Google please disable Javascript for this site. This site is perfectly usable without Javascript.
Last modified: March 12, 2019