In Ubuntu, you can bind an IP address to a specific network interface and check the network interfaces using various commands. Below are the steps to achieve this:
1. Check Network Interfaces
To list all network interfaces and their configurations, you can use the ip
command or ifconfig
.
Using ip
command:
ip addr show
or
ip a
Using ifconfig
(if installed):
ifconfig
2. Bind an IP Address to a Network Interface
Using ip
command (temporary):
sudo ip addr add <IP_ADDRESS>/<SUBNET_MASK> dev <INTERFACE_NAME>
Example
sudo ip addr add 192.168.1.100/24 dev eth0
Using netplan
(persistent):
Ubuntu uses netplan
for network configuration. You can edit the configuration file located in /etc/netplan/
Open the configuration file:
sudo nano /etc/netplan/<configuration_filename.yaml
for BIND A SINGLE IP - Replace
network:
version: 2
renderer: networkd
ethernets:
eth0:
addresses:
- 192.168.1.100/24 #Replace with your primary IP and subnet mask
gateway4: 192.168.1.1 #Replace with your gateway IP
nameservers:
addresses: [8.8.8.8, 8.8.4.4]
for BIND 3 IPS - Replace
network:
version: 2
renderer: networkd
ethernets:
ens3:
dhcp4: no
addresses:
- 202.124.164.76/24 #Replace with your primary IP and subnet mask
- 202.124.164.73/24 #Replace with your secondary IP and subnet mask
- 202.124.164.230/24 #Replace with your tertiary IP and subnet mask
- 192.168.0.22/24 #Replace with your subnet of your primary IP
- 192.168.0.10/24 #Replace with your subnet of your secondary IP
- 192.168.0.198/24 #Replace with your subnet of your tertiary IP
routes:
- to: 0.0.0.0/0
via: 202.124.164.1 #Replace with your gateway IP
nameservers:
addresses:
- 8.8.8.8
- 8.8.4.4
Apply the changes:
sudo netplan apply
3. Verify the IP Binding
After binding the IP address, you can verify it using the ip
or ifconfig
command.
Using ip
command:
ip addr show dev <INTERFACE_NAME>
Example:
ip addr show dev eth0
Using ifconfig
:
ifconfig <INTERFACE_NAME>
Example:
ifconfig eth0
4. Check Network Connectivity
To ensure that the IP binding is working correctly, you can ping another device on the network.
ping <TARGET_IP>
Example:
ping 192.168.1.1
5. Restart Network Service (if needed)
If you encounter any issues, you can restart the network service.
Using systemctl
:
sudo systemctl restart networking
Using netplan
:
sudo netplan apply
This should now work without indentation errors.