A Comprehensive Guide to TCP/IP Configuration in Linux.

I decided to make a guide about TCP/IP configuration in Linux, and you may ask: well, what Linux distribution in specific? I know!, there are hundreds of Linux distribution, but for this guide, I’m only going to cover the two most used Linux distribution: Ubuntu and Fedora. Ubuntu is a Debian derivative, so the Ubuntu portion of TCP/IP configuration applies to any distro based on Debian. And the same goes for Fedora, which is based on RedHat Linux.

First, you want to find out what interfaces you have, and what ip address, “if any,” was assigned to your computer. For this use the “ifconfig” command:

ifconfig  #will list all enabled interfaces

if you are looking for a specific interface:

ifconfig eth0 #will only display the configuration for eth0 interface

If you get no interfaces other than the loopback address, it is time to do some troubleshooting and find out whether your network card was detected by Linux or not.

sudo lspci | grep -i ethernet #displaying all your ethernet cards

if you’re troubleshooting a wireless card just change “ethernet” for “wireless.”
other useful command when troubleshooting network card and drivers is “lsmod”


Dynamic TCP/IP:

By default Ubuntu starts in automatic TCP/IP configuration, this means that once Ubuntu starts, it will ask the DHCP server for an ip address. However, if you are using a distro that is not enabling the eth0 (network interface) at startup, you can do so manually.

sudo ifconfig eth0 up  #enabling the network interface

After you enable the interface, it is time to start the network service. This will contact the DHCP server and negotiate and ip address.

sudo /etc/init.d/networking start  #start networking all interfaces

And that’s all there is for dynamic ip configuration in Ubuntu.

Static TCP/IP:

Now, if you need to use static ip, you need to edit the “/etc/network/interfaces” file:

sudo gedit /etc/network/interfaces #edit the network interfaces file
auto lo
iface lo inet loopback
iface eth0 inet static

if you don’t know what is the correct network mask for your network or ip address, check out this article on calculating netmask.
Once you have finished adding your ip configuration, then proceed to reset your network srervice.

sudo /etc/init.d/networking restart #restarting networking


Dynamic TCP/IP:

If your Fedora distribution is set to get a dynamic ip; then, you probably don’t have to do anything; however, if the os starts and you don’t get an ip, a good rule of thumb is to start by enabling the ethernet card.

need root access!

ifconfig eth0 up  #bringing eth0 up

After enabling the interface, you should start the network service.

service network start  #starting network service

Static TCP/IP:

The file that contains the TCP/IP configuration in Fedora is different from its counterpart Ubuntu. In Fedora the file is: /etc/sysconfig/network-scripts/ifcfg-eth0
need root access!

vi /etc/sysconfig/network-scripts/ifcfg-eth0 #edit TCP/IP configuration

Usually, the resolve.conf file, which contains the DNS server ip address, gets its setting from “ifcfg-eth0” file, but if that’s not the case, you can update it.

vi /etc/resolv.conf  #DNS configuration file
# Generated by NetworkManager
Share This!

2 thoughts on “A Comprehensive Guide to TCP/IP Configuration in Linux.

Leave a Reply

Your email address will not be published.