this repo has no description
1# Network Configuration by Distribution
2
3## Viewing Current Configuration
4
5Show IP addresses:
6```bash
7ip a
8# or
9ip addr show
10```
11
12Show specific interface:
13```bash
14ip a show eth0
15```
16
17## Kali/Debian - /etc/network/interfaces
18
19**File**: `/etc/network/interfaces`
20
21Basic static configuration:
22```bash
23auto eth0
24iface eth0 inet static
25 address 172.20.118.100
26 netmask 255.255.255.0
27 gateway 172.20.118.1
28```
29
30**Key components:**
31- `auto eth0` - Bring up interface automatically on boot
32- `iface eth0 inet static` - Configure static IP (not DHCP)
33- `address` - IP address
34- `netmask` - Subnet mask
35- `gateway` - Default gateway (router)
36
37**Restart networking:**
38```bash
39sudo systemctl restart networking
40# or
41sudo ifdown eth0 && sudo ifup eth0
42```
43
44## CentOS/RHEL - ifcfg Files
45
46**Directory**: `/etc/sysconfig/network-scripts/`
47
48**Files**: One per interface (e.g., `ifcfg-eth0`, `ifcfg-eth1`)
49
50Example `ifcfg-eth0`:
51```bash
52DEVICE=eth0
53BOOTPROTO=static
54ONBOOT=yes
55IPADDR=172.20.118.1
56NETMASK=255.255.255.0
57GATEWAY=172.20.118.254
58```
59
60**Key settings:**
61- `DEVICE` - Interface name
62- `BOOTPROTO` - `static` or `dhcp`
63- `ONBOOT` - `yes` to auto-start on boot
64- `IPADDR` - IP address
65- `NETMASK` - Subnet mask
66- `GATEWAY` - Default gateway
67
68**Restart networking:**
69```bash
70sudo systemctl restart network
71# or per-interface:
72sudo ifdown eth0 && sudo ifup eth0
73```
74
75## Ubuntu - Netplan (YAML)
76
77**Directory**: `/etc/netplan/`
78
79**File**: Usually `01-network-manager-all.yaml` (or similar `.yaml` file)
80
81**IMPORTANT**: YAML is whitespace-sensitive. Use 2-space indentation consistently.
82
83Example configuration:
84```yaml
85network:
86 version: 2
87 renderer: NetworkManager
88 ethernets:
89 ens18:
90 addresses:
91 - 192.168.195.2/24
92 gateway4: 192.168.195.1
93```
94
95**Key elements:**
96- `ethernets:` - Section for ethernet interfaces
97- `ens18:` - Interface name (not eth0 on modern Ubuntu)
98- `addresses:` - List of IPs (note the dash and `/24` CIDR notation)
99- `gateway4:` - Default gateway for IPv4
100
101**Apply changes:**
102```bash
103sudo netplan apply
104```
105
106**Test configuration (doesn't persist):**
107```bash
108sudo netplan try
109```
110
111**CIDR notation:** `/24` equals `255.255.255.0`
112
113## Temporary IP Configuration
114
115Set IP temporarily (lost on reboot):
116```bash
117sudo ip addr add 192.168.1.100/24 dev eth0
118```
119
120Flush (remove) all IPs from interface:
121```bash
122sudo ip addr flush dev eth0
123```
124
125## Common Network Issues
126
1271. **Wrong interface name**: Check with `ip a` first
1282. **Typo in config file**: Double-check spelling and syntax
1293. **Forgotten gateway**: Can't reach beyond local network
1304. **Netplan spacing**: YAML requires exact indentation
1315. **Wrong subnet**: Devices must be on same subnet to communicate
132
133## Interface Naming
134
135- **Old style**: `eth0`, `eth1`, `lo` (loopback)
136- **New style**: `ens18`, `enp0s3`, etc. (Ubuntu/modern systems)
137- Always check actual names with `ip a` before configuring