Home > Articles > Operating Systems, Server > Linux/UNIX/Open Source

Setting Up TCP/IP on Linux

Dr. Karanjit Siyan shows you the steps you need to take to set up TCP/IP on Linux, from making sure the networking software is correctly installed to using graphical tools to configure network interfaces.

This article is excerpted from Chapter 28 of TCP/IP Unleashed by Karanjit Siyan (Sams Publishing: ISBN 0672323516).

This chapter is from the book

This chapter is from the book

Before configuring TCP/IP on your Linux system, you need to perform a few small steps to ensure that your filesystem is ready. The first step is to make sure the networking software has been installed. You can install the network package through the setup program, as shown in Figure 28.1. Selecting the networking option installs the applications you need to use TCP/IP under Linux.


Other distributions, notably RedHat, now have a GUI installation that makes installing the Linux system easier for the novice.

After the network software has been installed, you might have to reboot your system.

Figure 28.1 The Linux setup program lets you install the networking software easily.

Some versions of Linux (notably those that use the 2.0 kernel and many of the latest releases) require a /proc filesystem for networking to function properly. Most Linux kernels that inherently support networking automatically create the /proc filesystem when the operating system is installed, so you shouldn't have to do anything more than make sure it is properly mounted by the kernel. (The /proc filesystem is a quick interface point for the kernel to obtain network information, as well as to help the kernel maintain tables usually kept in the subdirectory /proc/net.) You can verify that your Linux version uses the /proc filesystem by trying to do a "cd /proc" command to change to the /proc directoryt, as shown in Figure 28.2.

Figure 28.2 If you can change into the /proc filesystem and obtain a directory listing, the filesystem exists and TCP/IP can be configured properly.

If you can't change into /proc, it probably doesn't exist (assuming you have access permissions, of course). If the /proc filesystem was not created for you by the Linux installation routine, you have to rebuild the kernel and select the /proc option. Change to the Linux source directory (such as /usr/src/Linux) and run the kernel configuration routine with this command:

make config

If you have X-Windows running and properly configured, you can run the following GUI-based configuration process:

make xconfig

When you are asked whether you want procfs support (or a similarly worded question), answer yes. If you do not get asked about the /proc filesystem support, and the /proc directory is not created on your filesystem, you need to upgrade your kernel to support networking.

The /proc filesystem should be mounted automatically when your Linux system boots. To force the /proc filesystem to be mounted automatically, edit the /etc/fstab file and add a line similar to this (if it isn't already there):

none     /proc     proc     defaults

Another step you should take before configuring TCP/IP is to set the system's hostname. To set the hostname, use this command:

hostname name

name is the system name you want for your local machine. If you have a full domain name assigned to your network and your machine, you can use that name for your system. For example, if your Linux machine is attached to the domain yacht.com and your machine's name is spinnaker, you can set the full domain name using this command:

hostname spinnaker.yacht.com

If you don't have a fully qualified domain name, you can make up your own domain name as long as you are not connected to the Internet. (A made-up domain name does not have any meaning outside your local area network.) Alternatively, you do not have to assign a domain at all for your machine, but can simply enter this short name:

hostname spinnaker

An entry is made in the /etc/hosts file to reflect your machine's name. You should verify that your machine's name appears in that file. You also need to know the IP address assigned to your machine. You should have a unique IP address ready for your Linux machine for use in the configuration process.

One file that you might need to work with if you plan to direct information across many networks is /etc/networks. The /etc/networks file contains a list of all the network names your machine should know about, along with their IP addresses. Applications use this file to determine target networks based on the network name. The /etc/networks file consists of two columns for the symbolic name of the remote network and its IP address. Most /etc/networks files have at least one entry for the loopback driver that should be on every Linux system (the loopback driver is used as a default IP address by some Linux applications and is discussed in more detail later in this chapter). A sample /etc/networks file looks like this:


This sample file has two networks entered in it with their network IP addresses. Only the network portion of the IP address is specified, leaving the host component of the IP addresses set to zeros.

Network Interface Access

You need to make the network interface accessible to the operating system and its utilities. This is done with the ifconfig command. When run, ifconfig makes the Network Layer of the kernel work with the network interface by giving it an IP address, then issuing the command to make the interface active. When the interface is active, the kernel can send and receive data through the interface.

You need to set up several interfaces for your machine, including the loopback driver and the Ethernet interface (I assume you are using Ethernet throughout this chapter, but you can use other interfaces). The ifconfig command is used for each interface in order. The syntax of the ifconfig command is

ifconfig interface_type IP_Address

where interface_type is the interface's device driver name (such as lo for loopback, ppp for PPP, and eth for Ethernet). IP_Address is the IP address used by that interface.

After the ifconfig command has been run and the interface is active, you use the route command to add or remove routes to the kernel's routing table. This is necessary to enable the local machine to find other machines. The syntax of the route command is

route add|del IP_Address

where either add or del is used to add or remove a route from the kernel's routing table, and IP_Address is the remote route being affected.

You can display the current contents of the kernel's routing table by entering the route command with no arguments. For example, if your system is set up only with a loopback driver, you will see this:

$ route
Kernel Routing Table
Destination  Gateway  Genmask  Flags MSS Window Use Iface
loopback     *  U  1936 0    16 lo


You can also display the routing table using the following command:

netstat -rn

The -r option displays the routing table and the -n option displays IP addresses instead of symbolic names.

The columns that you should be concerned with are the destination name, which shows the name of the configured target (in this case loopback), the mask to be used (Genmask), and the interface (Iface, in this case /dev/lo). You can force route to display the IP addresses instead of symbolic names by using the -n option:

$ route -n
Kernel Routing Table
Destination  Gateway  Genmask  Flags MSS Window Use Iface     *  U  1936 0    16 lo

As mentioned earlier in this section, a typical Linux network configuration includes a loopback interface (which should exist on every machine) and a network interface such as Ethernet. You can set these interfaces up in order.

Setting Up the Loopback Interface

A loopback interface should exist on every machine. It is used by some applications that require an IP address in order to function properly, which may not exist if the Linux system is not configured for networking. The loopback driver is also used as a diagnostic utility by some TCP/IP applications. The loopback interface has the IP address, so the /etc/hosts file should have an entry for this interface.


A loop back address is any address of the form 127.x.x.x where x is a number from 0 to 255. The address of is commonly used as a loopback address for historical reasons. This was the format in which the loopback address was specified in the /etc/hosts file on UNIX systems.

A loopback driver might have been created by the kernel during software installation, so check the /etc/hosts file for a line similar to this:


If such a line exists, the loopback driver is already in place and you can continue to the Ethernet interface. If you are not sure about the /etc/hosts file, you can use the ifconfig utility to display all the information it knows about the loopback driver. Use this command:

ifconfig lo

You should see several lines of information. If you get an error message, the loopback driver does not exist.

If the loopback interface is not in the /etc/hosts file, you need to create it with the ifconfig command. The following command creates the necessary line in /etc/hosts:

ifconfig lo

You can view the specifics of the newly created loopback driver with ifconfig. For example, the following command shows the loopback driver's typical configuration:

$ ifconfig lo
lo       Link encap: Local Loopback
inet addr Bcast {NONE SET] Mask
RX packets:0 errors:0 dropped:0 overruns:0
TX packets:0 errors:0 dropped:0 overruns:0

As long as the loopback driver's details are shown as output from the ifconfig command, all is well with that interface. After checking the ifconfig routine, you should add the loopback driver to the kernel routing tables with one of these two commands:

route add
route add localhost

It doesn't matter which command you use. As a quick check that all is correct with the loopback driver, you can use the ping command to check the routing. If you issue this command:

ping localhost

you should see output like this:

PING localhost: 56 data bytes
64 bytes from icmp_seq=0. ttl=255 time=1 ms
64 bytes from icmp_seq=1. ttl=255 time=1 ms
64 bytes from icmp_seq=2. ttl=255 time=1 ms
64 bytes from icmp_seq=3. ttl=255 time=1 ms
64 bytes from icmp_seq=4. ttl=255 time=1 ms
64 bytes from icmp_seq=5. ttl=255 time=1 ms
64 bytes from icmp_seq=6. ttl=255 time=1 ms
64 bytes from icmp_seq=7. ttl=255 time=1 ms
 localhost PING Statistics 
7 packets transmitted, 7 packets received, 0% packet loss
round-trip (ms) min/avg/max = 1/1/1

The ping command's progress was interrupted by issuing a Ctrl+C. If you get no output from the ping command, the localhost name wasn't recognized. Check the configuration files and route entry again and repeat the ping to the loopback address.

Setting Up the Ethernet Interface

You can follow the same procedure to set up the Ethernet driver. You use ifconfig to tell the kernel about the interface, then add the routes to the remote machines on the network. If the network is attached to your machine, you can test the connections immediately with the ping command.

Set up the Ethernet interface using ifconfig. To make the interface active, use the ifconfig command with the Ethernet device name (usually eth0) and your IP address. For example, use the following command to set up your system with the IP address

ifconfig eth0

You don't have to specify the network mask with the ifconfig command because it can deduce the proper value from the IP address. If you want to provide the network mask value explicitly, append it to the command line with the keyword netmask:

ifconfig eth0 netmask

You can check the interface with the ifconfig command using this Ethernet interface name:

$ ifconfig eth0
eth0         Link encap 10Mps: Ethernet Hwaddr
inet addr Bcast Mask
RX packets:0 errors:0 dropped:0 overruns:0
TX packets:0 errors:0 dropped:0 overruns:0

You might notice in the output that the broadcast address is set based on the local machine's IP address. This is used by TCP/IP to access all machines on the local area network at once. The Maximum Transfer Unit (MTU) size is usually set to the maximum value of 1500 (for Ethernet networks).

Next, you need to add an entry to the kernel routing tables to let the kernel know the local machine's network address. The IP address that is used with the route command to do this is that of the network as a whole, without the local identifier. To set the entire local area network at once, the -net option of the route command is used. In the case of the IP addresses shown earlier, the command is

route add -net

This command adds all the machines on the local area network identified by the network address 147.123.20 to the kernel's list of accessible machines. If you didn't do it this way, you would have to manually enter the IP address of each machine on the network. An alternative is to use the /etc/networks file to specify only the network portions of the IP addresses. The /etc/networks file might contain a list of network names and their IP addresses. If you have an entry in the /etc/networks file for a network called foobar_net, you could add the entire network to the routing table with this command:

route add foobar_net

Using the /etc/networks file approach has the security problem that any machine on that network is granted access. This may not be what you want.

After the route has been added to the kernel routing tables, you can try the Ethernet interface. To ping another machine (assuming you are connected to the Ethernet cable, of course), you need either its IP address or its name (which is resolved either by the /etc/hosts file or a service like DNS). The command and output looks like this:

tpci_sco1-45> ping 
PING 64 data bytes
64 bytes from icmp_seq=0. time=20. ms
64 bytes from icmp_seq=1. time=10. ms
64 bytes from icmp_seq=2. time=10. ms
64 bytes from icmp_seq=3. time=20. ms
64 bytes from icmp_seq=4. time=10. ms
64 bytes from icmp_seq=5. time=10. ms
64 bytes from icmp_seq=6. time=10. ms
^C PING Statistics 
7 packets transmitted, 7 packets received, 0% packet loss
round-trip (ms) min/avg/max = 10/12/20

If you don't get anything back from the remote machine, verify that the remote is connected and you are using the proper IP address. If all is well there, check the configuration and route commands. If that checks out, try pinging another machine.

After these steps are completed, your Linux system should be able to access any machine on the local area network through TCP/IP. If you are on a small network, that's all you really have to do. On larger networks, or those that implement special protocols or employ gateways, you need to take a few more configuration steps. These steps are covered in the following sections.

If you want to allow a few other machines on the TCP/IP network to access your Linux machine, you can put their names and IP addresses in the /etc/hosts file. Figure 28.3 shows a sample /etc/hosts file with a name and possible variations (such as godzilla and godzilla.tpci), and its IP address. That machine (which can be any operating system running TCP/IP) can now connect to your Linux system using telnet, ftp, or a similar utility. Of course, a user on the remote machine can't log in unless you set up an account for him. If the name of a remote machine is in the /etc/hosts file, you can also telnet or ftp to that machine using either its name or IP address.

Figure 28.3 This /etc/hosts file lets remote machines connect to the Linux server.

InformIT Promotional Mailings & Special Offers

I would like to receive exclusive offers and hear about products from InformIT and its family of brands. I can unsubscribe at any time.


Pearson Education, Inc., 221 River Street, Hoboken, New Jersey 07030, (Pearson) presents this site to provide information about products and services that can be purchased through this site.

This privacy notice provides an overview of our commitment to privacy and describes how we collect, protect, use and share personal information collected through this site. Please note that other Pearson websites and online products and services have their own separate privacy policies.

Collection and Use of Information

To conduct business and deliver products and services, Pearson collects and uses personal information in several ways in connection with this site, including:

Questions and Inquiries

For inquiries and questions, we collect the inquiry or question, together with name, contact details (email address, phone number and mailing address) and any other additional information voluntarily submitted to us through a Contact Us form or an email. We use this information to address the inquiry and respond to the question.

Online Store

For orders and purchases placed through our online store on this site, we collect order details, name, institution name and address (if applicable), email address, phone number, shipping and billing addresses, credit/debit card information, shipping options and any instructions. We use this information to complete transactions, fulfill orders, communicate with individuals placing orders or visiting the online store, and for related purposes.


Pearson may offer opportunities to provide feedback or participate in surveys, including surveys evaluating Pearson products, services or sites. Participation is voluntary. Pearson collects information requested in the survey questions and uses the information to evaluate, support, maintain and improve products, services or sites, develop new products and services, conduct educational research and for other purposes specified in the survey.

Contests and Drawings

Occasionally, we may sponsor a contest or drawing. Participation is optional. Pearson collects name, contact information and other information specified on the entry form for the contest or drawing to conduct the contest or drawing. Pearson may collect additional personal information from the winners of a contest or drawing in order to award the prize and for tax reporting purposes, as required by law.


If you have elected to receive email newsletters or promotional mailings and special offers but want to unsubscribe, simply email information@informit.com.

Service Announcements

On rare occasions it is necessary to send out a strictly service related announcement. For instance, if our service is temporarily suspended for maintenance we might send users an email. Generally, users may not opt-out of these communications, though they can deactivate their account information. However, these communications are not promotional in nature.

Customer Service

We communicate with users on a regular basis to provide requested services and in regard to issues relating to their account we reply via email or phone in accordance with the users' wishes when a user submits their information through our Contact Us form.

Other Collection and Use of Information

Application and System Logs

Pearson automatically collects log data to help ensure the delivery, availability and security of this site. Log data may include technical information about how a user or visitor connected to this site, such as browser type, type of computer/device, operating system, internet service provider and IP address. We use this information for support purposes and to monitor the health of the site, identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents and appropriately scale computing resources.

Web Analytics

Pearson may use third party web trend analytical services, including Google Analytics, to collect visitor information, such as IP addresses, browser types, referring pages, pages visited and time spent on a particular site. While these analytical services collect and report information on an anonymous basis, they may use cookies to gather web trend information. The information gathered may enable Pearson (but not the third party web trend services) to link information with application and system log data. Pearson uses this information for system administration and to identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents, appropriately scale computing resources and otherwise support and deliver this site and its services.

Cookies and Related Technologies

This site uses cookies and similar technologies to personalize content, measure traffic patterns, control security, track use and access of information on this site, and provide interest-based messages and advertising. Users can manage and block the use of cookies through their browser. Disabling or blocking certain cookies may limit the functionality of this site.

Do Not Track

This site currently does not respond to Do Not Track signals.


Pearson uses appropriate physical, administrative and technical security measures to protect personal information from unauthorized access, use and disclosure.


This site is not directed to children under the age of 13.


Pearson may send or direct marketing communications to users, provided that

  • Pearson will not use personal information collected or processed as a K-12 school service provider for the purpose of directed or targeted advertising.
  • Such marketing is consistent with applicable law and Pearson's legal obligations.
  • Pearson will not knowingly direct or send marketing communications to an individual who has expressed a preference not to receive marketing.
  • Where required by applicable law, express or implied consent to marketing exists and has not been withdrawn.

Pearson may provide personal information to a third party service provider on a restricted basis to provide marketing solely on behalf of Pearson or an affiliate or customer for whom Pearson is a service provider. Marketing preferences may be changed at any time.

Correcting/Updating Personal Information

If a user's personally identifiable information changes (such as your postal address or email address), we provide a way to correct or update that user's personal data provided to us. This can be done on the Account page. If a user no longer desires our service and desires to delete his or her account, please contact us at customer-service@informit.com and we will process the deletion of a user's account.


Users can always make an informed choice as to whether they should proceed with certain services offered by InformIT. If you choose to remove yourself from our mailing list(s) simply visit the following page and uncheck any communication you no longer want to receive: www.informit.com/u.aspx.

Sale of Personal Information

Pearson does not rent or sell personal information in exchange for any payment of money.

While Pearson does not sell personal information, as defined in Nevada law, Nevada residents may email a request for no sale of their personal information to NevadaDesignatedRequest@pearson.com.

Supplemental Privacy Statement for California Residents

California residents should read our Supplemental privacy statement for California residents in conjunction with this Privacy Notice. The Supplemental privacy statement for California residents explains Pearson's commitment to comply with California law and applies to personal information of California residents collected in connection with this site and the Services.

Sharing and Disclosure

Pearson may disclose personal information, as follows:

  • As required by law.
  • With the consent of the individual (or their parent, if the individual is a minor)
  • In response to a subpoena, court order or legal process, to the extent permitted or required by law
  • To protect the security and safety of individuals, data, assets and systems, consistent with applicable law
  • In connection the sale, joint venture or other transfer of some or all of its company or assets, subject to the provisions of this Privacy Notice
  • To investigate or address actual or suspected fraud or other illegal activities
  • To exercise its legal rights, including enforcement of the Terms of Use for this site or another contract
  • To affiliated Pearson companies and other companies and organizations who perform work for Pearson and are obligated to protect the privacy of personal information consistent with this Privacy Notice
  • To a school, organization, company or government agency, where Pearson collects or processes the personal information in a school setting or on behalf of such organization, company or government agency.


This web site contains links to other sites. Please be aware that we are not responsible for the privacy practices of such other sites. We encourage our users to be aware when they leave our site and to read the privacy statements of each and every web site that collects Personal Information. This privacy statement applies solely to information collected by this web site.

Requests and Contact

Please contact us about this Privacy Notice or if you have any requests or questions relating to the privacy of your personal information.

Changes to this Privacy Notice

We may revise this Privacy Notice through an updated posting. We will identify the effective date of the revision in the posting. Often, updates are made to provide greater clarity or to comply with changes in regulatory requirements. If the updates involve material changes to the collection, protection, use or disclosure of Personal Information, Pearson will provide notice of the change through a conspicuous notice on this site or other appropriate way. Continued use of the site after the effective date of a posted revision evidences acceptance. Please contact us if you have questions or concerns about the Privacy Notice or any objection to any revisions.

Last Update: November 17, 2020