Swiftorial Logo
Home
Swift Lessons
Matchups
CodeSnaps
Tutorials
Career
Resources

Network Configuration Tutorial

Introduction

Network configuration is essential for any system administrator or user who needs to set up, manage, and troubleshoot network connections on a Linux system. This tutorial will cover the basics of network configuration, including setting up IP addresses, configuring DNS, and ensuring proper routing.

Checking Current Network Configuration

Before making any changes, it’s important to check the current network configuration. This can be done using the ifconfig or ip commands.

Example:

ifconfig
eth0: flags=4163  mtu 1500
    inet 192.168.1.100  netmask 255.255.255.0  broadcast 192.168.1.255
    inet6 fe80::1a2b:3c4d:5e6f:7g8h  prefixlen 64  scopeid 0x20
    ether 00:1a:2b:3c:4d:5e  txqueuelen 1000  (Ethernet)
    RX packets 12345  bytes 1234567 (1.2 MB)
    TX packets 12345  bytes 1234567 (1.2 MB)

Setting Up a Static IP Address

To set up a static IP address, you need to edit the network configuration file. The location of this file varies depending on the Linux distribution. For instance, on Ubuntu, it’s usually found in /etc/network/interfaces.

Edit the file to include the following lines:

auto eth0
iface eth0 inet static
    address 192.168.1.100
    netmask 255.255.255.0
    gateway 192.168.1.1
                    

After editing the file, restart the networking service to apply the changes:

sudo systemctl restart networking

Configuring DNS

DNS configuration is important for resolving domain names. This is typically set in the /etc/resolv.conf file. Add the following lines to set up DNS servers:

nameserver 8.8.8.8
nameserver 8.8.4.4
                    

These are Google's public DNS servers. You can replace them with your preferred DNS servers.

Routing Configuration

Routing determines how packets are forwarded from one network to another. To view the current routing table, use the route or ip route command.

Example:

route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         192.168.1.1     0.0.0.0         UG    0      0        0 eth0
192.168.1.0     0.0.0.0         255.255.255.0   U     0      0        0 eth0
                    

To add a new route, use the following command:

sudo route add -net 10.0.0.0 netmask 255.0.0.0 gw 192.168.1.1

Network Troubleshooting

Troubleshooting network issues can be challenging. Here are some basic commands to help diagnose problems:

  • ping: Checks connectivity to a host.
  • traceroute: Traces the route packets take to a destination.
  • netstat: Displays network connections, routing tables, interface statistics, masquerade connections, and multicast memberships.
  • ifconfig or ip addr: Displays network interface configuration.

Example - Ping a host:

ping google.com
PING google.com (172.217.15.110) 56(84) bytes of data.
64 bytes from ord30s21-in-f14.1e100.net (172.217.15.110): icmp_seq=1 ttl=52 time=10.5 ms
64 bytes from ord30s21-in-f14.1e100.net (172.217.15.110): icmp_seq=2 ttl=52 time=10.6 ms
                    

Conclusion

Network configuration is a fundamental skill for managing Linux systems. This tutorial covered the basics of checking network configurations, setting up static IP addresses, configuring DNS, managing routing, and basic troubleshooting commands. With these tools, you should be able to effectively manage and troubleshoot network connections on your Linux system.