Networking On Linux 1730866187
Networking On Linux 1730866187
Networking on linux
1. Getting Info About the Network Interfaces
( ifconfig , ip , route )
ifconfig, ip , and route are essential commands for managing network
interfaces in Linux. ifconfig displays network interface details, while ip is a
more modern tool for configuring IP addresses and routes. The route command
shows and modifies the IP routing table, helping manage network traffic paths.
Using ifconfig
ifconfig enp0s3 , ip addr show dev enp0s3 : Display info about a specific
interface.
Using ip
Using route
Networking on linux 1
2. Setting the Network Interfaces
a. Disabling an interface
b. Activating an interface.
ifconfig enp0s3 up
ifconfig -a
Using route
Using ip
Using ifconfig
Networking on linux 2
ifconfig enp0s3 up
Using ip
yamlCopy code
network:
version: 2
renderer: networkd
ethernets:
enp0s3:
dhcp4: false
addresses:
- 192.168.0.20/24
gateway4: "192.168.0.1"
nameservers:
addresses:
- "8.8.8.8"
- "8.8.4.4"
Networking on linux 3
sudo netplan apply : Apply the new Netplan configuration.
sshd is the SSH server (daemon) and ssh or putty is the client.
Ubuntu: sudo apt update && sudo apt install openssh-server openssh-client
sudo systemctl status ssh : Checking the status of the SSH service.
# Ubuntu
sudo systemctl status ssh # Check SSH status
Networking on linux 4
sudo systemctl stop ssh # Stop SSH service
sudo systemctl restart ssh # Restart SSH service
sudo systemctl enable ssh # Enable SSH to start on boo
sudo systemctl is-enabled ssh # Check if SSH is enabled o
# CentOS
sudo systemctl status sshd # Check SSH status
sudo systemctl stop sshd # Stop SSH service
sudo systemctl restart sshd # Restart SSH service
sudo systemctl enable sshd # Enable SSH to start on bo
sudo systemctl is-enabled sshd # Check if SSH is enabled o
7. Other configurations:
a. ClientAliveInterval 300
b. ClientAliveCountMax 0
c. MaxAuthTries 2
d. MaxStartUps 3
e. LoginGraceTime 20
Networking on linux 5
scp (Secure Copy) and rsync are powerful command-line tools used for
transferring files between local and remote systems securely. scp uses SSH to
copy files with encryption, ensuring data security during transfer. It's simple
but doesn't handle partial transfers efficiently. rsync , on the other hand, is more
versatile, offering features like incremental file transfer, bandwidth control, and
file synchronization. It only transfers the changed parts of files, making it faster
and more efficient for syncing large directories or performing regular backups.
SCP
scp a.txt [email protected]:~ : Copy a local file to a remote destination.
RSYNC
sudo rsync -av /etc/ ~/etc-backup/ : Synchronize a directory.
exclude.txt example:
.avi
music/
abc.mkv
:
sudo rsync -av -e 'ssh -p 2267' /etc/ [email protected]:~/etc-backup/
Synchronize a directory over the network using SSH with a custom port.
Networking on linux 6
6. WGET - File Downloading Tool
wget is a command-line utility used for downloading files from the web. It
supports HTTP, HTTPS, and FTP protocols, making it a versatile tool for
retrieving content from remote servers. One of its key features is the ability to
resume interrupted downloads, ensuring reliable file transfers. Additionally,
wget can download entire websites for offline viewing, making it a powerful tool
for managing downloads and automating data retrieval in scripts.
a. Installing Wget
b. Downloading Files
wget https://cdimage.kali.org/kali-2020.2/kali-linux-2020.2-installer-amd64.iso :
Download a file to the current directory.
wget -c https://cdimage.kali.org/kali-2020.2/kali-linux-2020.2-installer-
d. Background Downloads
e. Downloading Websites
Networking on linux 7
wget --mirror --convert-links --adjust-extension --page-requisites --no-parent
7. NETSTAT and SS
netstat is a command-line tool used for displaying network connections,
routing tables, interface statistics, and more. It helps in monitoring network
activity, troubleshooting issues, and seeing which ports are open or being used
by different processes. However, it is gradually being replaced by ss due to its
faster performance and more detailed output.
ss (Socket Statistics) is a more modern and efficient utility than netstat for
displaying socket-related information. It provides detailed statistics on active
connections, showing TCP, UDP, and Unix sockets. It is faster, consumes fewer
resources, and offers advanced filtering options to narrow down the network
data you need to analyze.
lsof -c sshd : List all files opened by a specific process (e.g., sshd).
lsof -iTCP -sTCP:LISTEN -nP : List open TCP ports, showing numeric
addresses without resolving hostnames.
Networking on linux 8
9. Scanning Hosts and Networks using Nmap
nmap (Network Mapper) is a powerful open-source tool used for network
discovery and security auditing. It is widely used by network administrators and
penetration testers to identify hosts and services on a network, detect open
ports, and determine potential vulnerabilities. With various scanning
techniques, nmap can detect operating systems, identify running services, and
create a comprehensive network map, making it an essential tool for network
security and troubleshooting. Only scan your own hosts and servers. Scanning
networks is your responsibility.
a. Basic Scans
nmap -sS 192.168.0.1 : Perform a SYN scan (half-open scan, requires root).
b. Port Scans
nmap -Pn 192.168.0.0/24 : Treat all hosts as online and skip host discovery.
nmap -p 80 -iL hosts.txt : Read target IPs from a file and scan port 80.
Networking on linux 9