The days before home networks
Once upon a time, there was something called a "standalone Computer" -- one that was used to perform some specific task and didn't require other devices or a network interface to do its job. It might have allowed its owner to write essays, play games, or manage family finances, but all data was stored and processed locally. And, if there was a printer involved, it was a "slave" printer -- one that hung off a port on the system and wasn't shared unless someone carried it to another computer. My first home computer was a standalone and my neighbors at the time thought I was some kind of freak just for having computer in my home, never mind having it sitting on a desk in the corner of my dining room. At the time, this identified me as being clearly abnormal, though I'd bet today these same people all have home computers and can't imagine going through life without them. Standalones may still exist today and their isolation may work to their advantage, but they are very rare. These days, nearly all computers are hooked to networks and are able to connect to systems around the globe. Unix/Linux systems are no exception. This kind of connectivity changes relationships between families, friends, and people with shared interests dramatically. I hear from my sister far more often than the 2,920 miles between us would allow if facebook and gmail didn't provide a way for us to share the fairly trivial news from our day-to-day lives. And I recently met a 5th cousin once removed on linkedin. That's fairly incredible and something I'd never have had the patience or the tools to pull off 20 years ago.
The scene today
Instead of a standalone computer, today most people I know now have a home network. They have multiple computers connected to a private LAN, maybe a printer or two, and maybe even a large capacity network drive for backups. And some of those home networks include a mix of Windows and Linux systems. So, what do you need to know if one or more of those computers is a Linux system? What do you need to know if you're going to be setting up network connections on Linux systems at work?
Setting up your network connection
Whether at home or at work, if you're configuring a system to act as a Linux server, you will need to assign it what is called a "static" address. Static means it doesn't change. Server means that other systems need to find and connect to it. A static address is necessary so that clients, when they need to initiate connections, have a known address to use for these connections. For non-servers or "client" systems, addresses can be assigned dynamically and generally are -- whether they are assigned an address by a local router (as I have in my home) or by a DHCP server that manages this role within an organization. Even if your system is assigned an address dynamically, this doesn't mean that the address will change every time you boot it. Even DHCP addresses tends to be stable for a while. There is some likelihood that the same IP address will be assigned to a system for weeks, even months -- just no guarantee. As I like to tell my students, clients need to be able to find servers like shoppers need to find supermarkets. Servers never need to find their clients and supermarkets don't need to find their customers. Since clients initiate the connections, they can be coming from nearly anywhere.
Examining your network interfaces
To view your network settings, you would use the ifconfig command. If you try this command and get an error that claims the command cannot be found, it is likely that /sbin is not on your search path. You can try typing /sbin/ifconfig instead or you can modify your search path and then try ifconfig again.
$ ifconfig -bash: ifconfig: command not found $ PATH=$PATH:/sbin $ ifconfig eth0 Link encap:Ethernet HWaddr 00:16:35:69:BD:79 inet addr:192.168.0.11 Bcast:192.168.0.255 Mask:255.255.255.0 inet6 addr: fe80::212:ff35:fe69:bd12/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:16791460 errors:0 dropped:0 overruns:0 frame:0 TX packets:30066639 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:2182259898 (2.0 GiB) TX bytes:3951206845 (3.6 GiB) Interrupt:209 Memory:fdef0000-fdf00000 lo 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:32098 errors:0 dropped:0 overruns:0 frame:0 TX packets:32098 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:3227365 (3.0 MiB) TX bytes:3227365 (3.0 MiB)
Output like that shown above tells you a number of things. It tells you that the local network is a private network. You can tell this by the IP address shown in the second line. Any IP address that starts with 192.168 is part of a private address range. Many home networks will make use of a local router that assigns addresses like these to systems on the LAN as they boot. You can also tell, by looking at the 255.255.255.0 mask, that this network is capable of accommodating hundreds of systems, even if the router only provides eight ports. In today's typical home network, systems are likely to use wireless networking, so the number of available ports on the router isn't particularly significant. We can also see that the network interface is operational (RUNNING), view some numbers that tell us that data is going out and coming in (RX and TX packets), and note that a second network interface is listed. This second interface (i.e., the "lo" interface) is the "loopback". This interface is used by the system to communicate with itself. You should always see a loopback interface in your ifconfig output and it should always have the address 127.0.0.1. This address isn't used for anything else.
Where does your IP address come from?
Most likely, your IP address for both your home systems and the one that may be sitting on your desk at work are assigned addresses dynamically. And most likely, those addresses fall into one of the address ranges that can only be used internally and can be used by anyone. Those address ranges are:
<b><u>Range Decimal values # of addresses</u></b> 10.0.0.0-10.255.255.255 167772160-184549375 16777216 172.16.0.0-172.31.255.255 2886729728-2887778303 1048576 192.168.0.0-192.168.255.255 3232235520-3232301055 65536
Most home networks use IP addresses in the 192.168.0.0/24 (i.e., the bottom line shown above) because so many of the small network routers available today are set up to assign these addresses. You might notice that the first address range shown up is the largest of the three. This address range includes more than 16 million addresses. For this reason, it's the network address range that many organizations use for their internal systems, though most will only use a small portion of the available addresses. The second range contains more than 1 million address and the third more than 65,000. Most organizations will, of course, only use a small subset of the addresses in whatever range they choose to use.
Networks big and small
When organizations use the 10.0.0.0/8 (i.e., the top network range above), they generally break it into many smaller network segments to limit the amount of network traffic that traverses each segment, avoiding high collision rates (when "packets" interfere with each other) and network slowdowns. Other IP address ranges are public. This means that they can only be used by their registered "owners" and that they can be used to move data over the Internet. Private addresses can only be used inside private networks. Most organizations today use a private address range for their internal systems and a handful of public addresses that allow their web sites, email servers and other public-facing systems to be generally accessible. Of course, your home system can communicate over the Internet, but only because your connection goes through some kind of device that translates its IP address from an internal address to a public address as needed. If you were to log into a remote system from your home network and then run a command that shows where that remote system thinks you are coming from, you would *not* see your private IP, but the translated address that your router or cable modem provides. The 188.8.131.52 address shown below is not my system's IP address.
$ who shs pts/0 2014-03-08 18:09 (184.108.40.206)
Other useful commands
The netstat -r command is another good command to know. It displays the routing table on your system. Think of a routing table as one that tells your system "If you want to reach System X, go this way". In the routing table below, connections to any address in the 192.168.0.x or 169.254.x.x ranges are local while, if you want to reach any systems on any other address ranges, your connection requests will be sent to 192.168.0.1 and then forwarded from there.
$ netstat -r Kernel IP routing table Destination Gateway Genmask Flags MSS Window irtt Iface 192.168.0.0 * 255.255.255.0 U 0 0 0 eth0 169.254.0.0 * 255.255.0.0 U 0 0 0 eth0 10.1.0.0 192.168.0.2 255.255.0.0 U 0 0 0 eth0 default 192.168.0.1 0.0.0.0 UG 0 0 0 eth0
The "default" entry represents what is called your "default router". This address represents where your connections are sent whenever the systems you're trying to reach are 1) not on the subnet your system is attached to and 2) not on another subnet that is listed in the routing table. Another basic command that you need to know is ping. This command can help you determine if you can reach a remote system. For example, a command such as ping remhost.whatever.org might tell you whether that system is up and running. It's also useful, however, for confirming that your system is connecting properly to the local network. If you can ping a system that is across the Internet somewhere, you will know that your system is both connecting to the local network and able to reach beyond. The only problem with ping is that the lack of a response does not necessarily mean that the system you are trying to reach is down or that your network connection is hosed. The ping command or the entire protocol family of which it is a part of may be blocked before it gets to the remote system or before the response gets back to you. Another useful command that will provide you with a lot of insights into how connections are made with remote systems is traceroute. This command will display the route taken to reach the remote host and, along with the stops it makes, provide some timing information that shows how long each leg in the route is taking. This kind of information can come in handy when troubleshooting connection problems as it can show you where connections are breaking down.
$ traceroute server1.abc123.com traceroute to server1.abc123.com (220.127.116.11), 30 hops max, 40 byte packets 1 pix (192.168.0.1) 0.460 ms 0.417 ms 0.392 ms 2 * * * 3 gig1-core.net.umx.org (18.104.22.168) 11.011 ms 10.986 ms 10.500 ms ... 15 server1.abc123.com (22.214.171.124) 22.824 ms 24.296 ms 23.553 ms
We'll look at some additional aspects of networking on Unix and Linux systems in next week's post.
Read more of Sandra Henry-Stocker's Unix as a Second Language blog and follow the latest IT news at ITworld, Twitter and Facebook.