10 helpful “ip” instructions to configure network interfaces
Contents
- How do you Configure Static Ip Ip Address (IPv4)
- How do you Configure Static Ip Ip Address (IPv4)
- 1. How you can Assign a Ip to a particular Interface
- 2. How you can Check an Ip
- 3. How you can Remove an Ip
- 4. How you can Enable Network Interface
- 5. How you can Disable Network Interface
- 6. How do you Check Route Table?
- 7. How do you Add Static Route
- 8. How you can Remove Static Route
- 9. How do you Add Persistence Static Routes
- 10. How do you Add Default Gateway
Note: Please take configuration file backup prior to doing any changes.
How do you Configure Static Ip Ip Address (IPv4)
To configure static Ip, you have to update or edit network configuration file to assign an Static Ip to some system. You’ve got to be superuser with su (switch user) command from terminal or command prompt.
For RHEL/CentOS/Fedora
Open and edit network configuration apply for (eth0 or eth1) making use of your favorite editor. For instance, to assigning Ip to eth0 interface the following.
[root@tecmint ~]# mire /etc/sysconfig/network-scripts/ifcfg-eth0
Simple output:
DEVICE=”eth0″
BOOTPROTO=static
ONBOOT=yes
TYPE=”Ethernet”
IPADDR=192.168.50.2
NAME=”System eth0″
HWADDR=00:0C:29:28:FD:4C
GATEWAY=192.168.50.1
For Ubuntu/Debian/Linux Mint
Assign Static Ip to eth0 interface editing configuration file /etc/network/interfaces to create permanent changes as proven below.
auto eth0
iface eth0 inet static
address 192.168.50.2
netmask 255.255.255.
gateway 192.168.50.1
Note: Please take configuration file backup prior to doing any changes.
How do you Configure Static Ip Ip Address (IPv4)
To configure static Ip, you have to update or edit network configuration file to assign an Static Ip to some system. You’ve got to be superuser with su (switch user) command from terminal or command prompt.
For RHEL/CentOS/Fedora
Open and edit network configuration apply for (eth0 or eth1) making use of your favorite editor. For instance, to assigning Ip to eth0 interface the following.
[root@tecmint ~]# mire /etc/sysconfig/network-scripts/ifcfg-eth0
Simple output:
DEVICE=”eth0″
BOOTPROTO=static
ONBOOT=yes
TYPE=”Ethernet”
IPADDR=192.168.50.2
NAME=”System eth0″
HWADDR=00:0C:29:28:FD:4C
GATEWAY=192.168.50.1
For Ubuntu/Debian/Linux Mint
Assign Static Ip to eth0 interface editing configuration file /etc/network/interfaces to create permanent changes as proven below.
auto eth0
iface eth0 inet static
address 192.168.50.2
netmask 255.255.255.
gateway 192.168.50.1
Next, restart network services after entering every detail while using following command.
# /etc/init.d/networking restart
$ sudo /etc/init.d/networking restart
1. How you can Assign a Ip to a particular Interface
The next command accustomed to assign Ip to some specific interface (eth1) quickly.
# ip addr add 192.168.50.5 dev eth1
$ sudo ip addr add 192.168.50.5 dev eth1
Note: Regrettably each one of these settings is going to be lost following a system restart.
2. How you can Check an Ip
To obtain the depth information of the network interfaces like Ip, MAC Address information, make use of the following command as proven below.
# ip addr show
$ sudo ip addr show
Sample Output
1: lo: mtu 16436 qdisc noqueue condition UNKNOWN
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127…1/8 scope host lo
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: eth0: mtu 1500 qdisc pfifo_fast condition UNKNOWN qlen 1000
link/ether 00:0c:29:28:fd:4c brd ff:ff:ff:ff:ff:ff
inet 192.168.50.2/24 brd 192.168.50.255 scope global eth0
inet6 fe80::20c:29ff:fe28:fd4c/64 scope link
valid_lft forever preferred_lft forever
3: eth1: mtu 1500 qdisc pfifo_fast condition UNKNOWN qlen 1000
link/ether 00:0c:29:28:fd:56 brd ff:ff:ff:ff:ff:ff
inet 192.168.50.5/24 scope global eth1
inet6 fe80::20c:29ff:fe28:fd56/64 scope link
valid_lft forever preferred_lft forever
3. How you can Remove an Ip
The next command will remove a designated Ip in the given interface (eth1).
# ip addr del 192.168.50.5/24 dev eth1
$ sudo ip addr del 192.168.50.5/24 dev eth1
4. How you can Enable Network Interface
The “up” flag with interface name (eth1) enables a network interface. For instance, the next command will activates the eth1 network interface.
# ip link set eth1 up
$ sudo ip link set eth1 up
5. How you can Disable Network Interface
The “lower” flag with interface name (eth1) disables a network interface. For instance, the next command will De-activates the eth1 network interface.
# ip link set eth1 lower
$ sudo ip link set eth1 lower
6. How do you Check Route Table?
Type the next command to determine the routing table information of system.
# ip route show
$ sudo ip route show
Sample Output
10.10.20./24 via 192.168.50.100 dev eth0
192.168.160./24 dev eth1 proto kernel scope link src 192.168.160.130 metric 1
192.168.50./24 dev eth0 proto kernel scope link src 192.168.50.2
169.254../16 dev eth0 scope link metric 1002
default via 192.168.50.1 dev eth0 proto static
7. How do you Add Static Route
Why you ought to add Static routes or Manual routes, because the traffic mustn’t go through the default gateway. We have to add Static routes to pass through traffic from the easy way achieve the destination.
# ip route add 10.10.20./24 via 192.168.50.100 dev eth0
$ sudo ip route add 10.10.20./24 via 192.168.50.100 dev eth0
8. How you can Remove Static Route
To get rid of assigned static route, simply type the next command.
# ip route del 10.10.20./24
$ sudo ip route del 10.10.20./24
9. How do you Add Persistence Static Routes
All of the above route is going to be lost following a system restart. To include permanent Static route, edit file /etc/sysconfig/network-scripts/route-eth0 (We’re storing static route for (eth0) and add some following lines and save and exist. Automatically route-eth0 file won’t be there, have to be produced.
For RHEL/CentOS/Fedora
# mire /etc/sysconfig/network-scripts/route-eth0
10.10.20./24 via 192.168.50.100 dev eth0
For Ubuntu/Debian/Linux Mint
Open the file /etc/network/interfaces and also at the finish add some persistence Static routes. IP Addresses may vary inside your atmosphere.
$ sudo mire /etc/network/interfaces
auto eth0
iface eth0 inet static
address 192.168.50.2
netmask 255.255.255.
gateway 192.168.50.100
####################
up ip route add 10.10.20./24 via 192.168.50.100 dev eth0
Next, restart network services after entering every detail while using following command.
# /etc/init.d/network restart
$ sudo /etc/init.d/network restart
10. How do you Add Default Gateway
Default gateway could be specified globally or in interface-specific config file. Benefit of default gateway is that if we’ve several NIC exists within the system. You can include default gateway quickly as proven below command.
# ip route add default via 192.168.50.100
$ sudo ip route add default via 192.168.50.100
Kindly correct me basically overlooked. Please refer manual page doing man ip from terminal/command prompt to understand much more about IP Command.
Resourse: https://tecmint.com/ip-command-examples/