38 Configuring Interfaces with IP

Опубликовано: 02 Ноябрь 2024
на канале: Engineering Academy Online
No
0

Configuring Network Interfaces with `ip`

The `ip` command is a powerful tool for managing network interfaces in Linux, providing more functionality and flexibility than the older `ifconfig` command. It is part of the `iproute2` package and is widely used for configuring, managing, and monitoring network settings.

#### *Key Functions of the `ip` Command*

1. **Display Interface Information**: Show details about all network interfaces.
2. **Assign IP Addresses**: Configure static or dynamic IP addresses for interfaces.
3. **Enable/Disable Interfaces**: Bring interfaces up or down.
4. **Manage Routes**: Add, delete, or view routing entries.

Basic Usage of the `ip` Command

#### *1. Viewing Current Interface Configuration*

To view all network interfaces and their configurations, run:

```bash
ip addr show
```

This command displays information such as:
Interface name (e.g., `eth0`, `wlan0`)
Assigned IP addresses (both IPv4 and IPv6)
MAC address
Network mask

#### *2. Enabling or Disabling an Interface*

**To enable an interface**:
```bash
sudo ip link set dev eth0 up
```

**To disable an interface**:
```bash
sudo ip link set dev eth0 down
```

#### *3. Assigning an IP Address*

To assign a static IP address to an interface:

```bash
sudo ip addr add 192.168.1.100/24 dev eth0
```

**Explanation**:
`192.168.1.100`: The IP address you want to assign.
`/24`: The subnet mask (255.255.255.0).
`dev eth0`: Specifies the network interface.

#### *4. Deleting an IP Address*

To remove an IP address from an interface:

```bash
sudo ip addr del 192.168.1.100/24 dev eth0
```

#### *5. Managing Routes*

**To view the routing table**:
```bash
ip route show
```

**To add a default gateway**:
```bash
sudo ip route add default via 192.168.1.1
```

**To delete a route**:
```bash
sudo ip route del default via 192.168.1.1
```

Example Configuration Steps

1. **Display Current Configuration**:
```bash
ip addr show
```

2. **Bring Up the Interface**:
```bash
sudo ip link set dev eth0 up
```

3. **Assign an IP Address**:
```bash
sudo ip addr add 192.168.1.100/24 dev eth0
```

4. **Add a Default Gateway**:
```bash
sudo ip route add default via 192.168.1.1
```

5. **Verify the Configuration**:
```bash
ip addr show
ip route show
```

Conclusion

The `ip` command is a modern and comprehensive tool for configuring network interfaces in Linux. It provides enhanced capabilities for managing both basic and advanced networking tasks. Transitioning to `ip` from `ifconfig` is beneficial for anyone managing networks in Linux environments. If you have questions or need further clarification on using the `ip` command, feel free to ask!