-
Notifications
You must be signed in to change notification settings - Fork 0
Networking
Networking in Linux allows you to connect to the internet, share files, manage remote servers, and perform a wide range of communication tasks. Think of it as the "communication highway" of your computer, where data travels back and forth to connect with other devices. In Linux, there are several tools and commands to help you manage and troubleshoot your network connections.
Networking in Linux allows you to:
- Connect to the internet for browsing, downloading, and uploading files.
- Share files between computers in a network.
- Manage servers remotely, such as through SSH.
- Troubleshoot network issues to ensure smooth connectivity.
An IP (Internet Protocol) address is a unique address assigned to your computer or device on a network. Itβs like your home address on the internet, making sure that data sent to you arrives at the right place.
There are two types of IP addresses:
-
IPv4: Most common format, looks like
192.168.1.1. -
IPv6: Newer format, looks like
2001:0db8:85a3:0000:0000:8a2e:0370:7334.
A subnet mask is used to divide an IP address into network and host parts. It helps devices understand whether another device is on the same local network or if the data should be sent to a router for further routing.
DNS helps translate human-friendly domain names (like www.google.com) into IP addresses that computers can understand. Itβs like a phonebook for the internet, connecting names to numbers.
Linux offers a wide range of networking commands that allow you to view and configure network settings.
The ifconfig command is used to display or configure the network interfaces on your system.
To view the current network configuration:
ifconfigThis will display a list of network interfaces, their IP addresses, and other information.
The ip command is more modern and powerful than ifconfig. Itβs used to show and configure network settings.
To show all network interfaces and their configurations:
ip addrTo view the status of a specific interface (like eth0):
ip addr show eth0The route command is used to display or modify the routing table of your Linux system. The routing table is like a map that determines how data is forwarded to its destination.
To view the routing table:
route -nThe netstat command is used to display information about active network connections, routing tables, and interface statistics.
To see active network connections:
netstat -tuln-
-tshows TCP connections. -
-ushows UDP connections. -
-lshows only listening ports. -
-nshows numerical addresses instead of resolving domain names.
The ping command is used to test the network connection between your machine and another device on the network or the internet. It sends a small packet of data and waits for a reply, showing the round-trip time.
To ping a website:
ping www.google.comTo stop the ping command, press Ctrl + C.
To test your internet speed from the terminal, you can use the speedtest-cli tool.
First, install it using:
sudo apt-get install speedtest-cliTo run the speed test:
speedtest-cliThis will display the download and upload speeds of your internet connection.
The ss command is used to investigate socket connections on your system, like checking which ports are open and being used by applications.
To list all open ports:
ss -tulnThis shows active sockets and their listening ports.
Your Linux system can have multiple network interfaces, such as wired Ethernet (eth0), Wi-Fi (wlan0), or virtual network interfaces. You can manage these interfaces with tools like ifconfig, ip, or the more advanced nmcli for NetworkManager.
To bring a network interface up (enable):
sudo ifconfig eth0 upTo bring it down (disable):
sudo ifconfig eth0 downUsing ip:
To bring up an interface:
sudo ip link set eth0 upTo bring it down:
sudo ip link set eth0 downTo assign a static IP address to an interface (e.g., eth0), use the following command:
sudo ifconfig eth0 192.168.1.100 netmask 255.255.255.0 upUsing ip:
sudo ip addr add 192.168.1.100/24 dev eth0DNS settings are configured through a file called /etc/resolv.conf. To set a DNS server, edit the file using your preferred text editor.
For example, to use Googleβs public DNS:
sudo nano /etc/resolv.confAdd the following line:
nameserver 8.8.8.8
Save the file and exit.
Ensuring that your network is secure is very important. You can use tools like firewalls to control incoming and outgoing traffic.
ufw (Uncomplicated Firewall) is an easy-to-use front-end for iptables that simplifies firewall configuration.
To enable ufw:
sudo ufw enableTo check the status of ufw:
sudo ufw statusTo allow a service (e.g., HTTP):
sudo ufw allow httpTo block a service:
sudo ufw deny httpSSH (Secure Shell) is used to connect to a remote system securely over the network.
To connect to a remote system:
ssh username@remote_hostExample:
ssh lucy@192.168.1.10