2024-09-02 16:42:08 -06:00
# Linux Basic Network Configuration
## 1. Network Interfaces
Linux uses network interfaces to communicate with networks. Common interfaces include:
- eth0, eth1, etc.: Ethernet interfaces
- wlan0, wlan1, etc.: Wireless interfaces
- lo: Loopback interface
To list network interfaces:
2024-09-05 17:01:20 -06:00
`ip link show`
2024-09-02 16:42:08 -06:00
or
2024-09-05 17:01:20 -06:00
`ifconfig -a`
2024-09-02 16:42:08 -06:00
## 2. IP Address Configuration
### Temporary IP configuration:
- To set an IP address temporarily:
2024-09-05 17:01:20 -06:00
`sudo ip addr add 192.168.1.100/24 dev eth0`
2024-09-02 16:42:08 -06:00
- To remove an IP address:
2024-09-05 17:01:20 -06:00
`sudo ip addr del 192.168.1.100/24 dev eth0`
2024-09-02 16:42:08 -06:00
### Permanent IP configuration:
Edit the network configuration file (location varies by distribution):
- Ubuntu/Debian: /etc/network/interfaces
- CentOS/RHEL: /etc/sysconfig/network-scripts/ifcfg-eth0
Example configuration:
```
auto eth0
iface eth0 inet static
address 192.168.1.100
netmask 255.255.255.0
gateway 192.168.1.1
dns-nameservers 8.8.8.8 8.8.4.4
```
## 3. DHCP Configuration
For dynamic IP assignment, use DHCP:
```
auto eth0
iface eth0 inet dhcp
```
## 4. Network Manager
Many modern Linux distributions use Network Manager for easier network configuration. You can use the command-line tool 'nmcli' or GUI tools to manage connections.
## 5. Hostname Configuration
Set the hostname:
2024-09-05 17:01:20 -06:00
`sudo hostnamectl set-hostname new-hostname`
2024-09-02 16:42:08 -06:00
Update /etc/hosts file to include the new hostname.
## 6. DNS Configuration
Edit /etc/resolv.conf to set DNS servers:
```
nameserver 8.8.8.8
nameserver 8.8.4.4
```
Note: This file may be overwritten by DHCP. For permanent changes, configure your network manager or DHCP client.
## 7. Routing
View routing table:
2024-09-05 17:01:20 -06:00
`ip route show`
2024-09-02 16:42:08 -06:00
Add a static route:
2024-09-05 17:01:20 -06:00
`sudo ip route add 10.0.0.0/24 via 192.168.1.1 dev eth0`
2024-09-02 16:42:08 -06:00
## 8. Firewall Configuration
Most Linux distributions use iptables or nftables. Ubuntu uses ufw (Uncomplicated Firewall) as a frontend.
Enable UFW:
2024-09-05 17:01:20 -06:00
`sudo ufw enable`
2024-09-02 16:42:08 -06:00
Allow incoming SSH:
2024-09-05 17:01:20 -06:00
`sudo ufw allow ssh`
2024-09-02 16:42:08 -06:00
## 9. Network Diagnostics
- ping: Test connectivity
- traceroute: Trace packet route
- netstat or ss: Display network connections
- tcpdump: Capture and analyze network traffic
## 10. Network Service Management
Start/stop network service:
2024-09-05 17:01:20 -06:00
`sudo systemctl start networking`
`sudo systemctl stop networking`
2024-09-02 16:42:08 -06:00
Enable/disable network service at boot:
2024-09-05 17:01:20 -06:00
`sudo systemctl enable networking`
`sudo systemctl disable networking`
2024-09-02 16:42:08 -06:00
## 11. Wireless Network Configuration
Use 'iwconfig' to configure wireless interfaces:
2024-09-05 17:01:20 -06:00
`sudo iwconfig wlan0 essid "NetworkName" key s:password` #Not advised because it will leave your network password in the bash history!
2024-09-02 16:42:08 -06:00
2024-09-05 17:01:20 -06:00
For WPA networks, use 'wpa_supplicant'.
- `wpa_passphrase [ESSID] > /etc/wpa_supplicant/wpa_supplicanmt-[DEVICENAME].conf` . You will then be prompted to enter the password.
2024-09-02 16:42:08 -06:00
## 12. Network Bonding
Combine multiple network interfaces for redundancy or increased throughput. Edit /etc/network/interfaces:
```
auto bond0
iface bond0 inet static
address 192.168.1.100
netmask 255.255.255.0
gateway 192.168.1.1
bond-slaves eth0 eth1
bond-mode active-backup
bond-miimon 100
bond-primary eth0
```