How do i Configure Static IP Address Internet Protocol (IPv4)
# vi /etc/sysconfig/network-scripts/ifcfg-eth0
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
# /etc/init.d/networking restart
1. How to Assign a IP Address to Specific Interface
The following command used to assign IP Address to a specific interface (eth1) on the fly.
# ip addr add 192.168.50.5 dev eth1
2. How to Check an IP Address
To get the depth information of your network interfaces like IP Address, MAC Address information, use the following command as shown below.
# ip addr show
3. How to Remove an IP Address
The following command will remove an assigned IP address from the given interface (eth1).
# ip addr del 192.168.50.5/24 dev eth1
4. How to Enable Network Interface
The “up” flag with interface name (eth1) enables a network interface. For example, the following command will activates the eth1 network interface.
# ip link set eth1 up
5. How to Disable Network Interface
The “down” flag with interface name (eth1) disables a network interface. For example, the following command will De-activates the eth1 network interface.
# ip link set eth1 down
6. How do I Check Route Table?
Type the following command to check the routing table information of system.
# ip route show
7. How do I Add Static Route
Why you need to add Static routes or Manual routes, because that the traffic must not pass through the default gateway. We need to add Static routes to pass traffic from best way to reach the destination.
# ip route add 10.10.20.0/24 via 192.168.50.100 dev eth0
8. How to Remove Static Route
To remove assigned static route, simply type the following command.
# ip route del 10.10.20.0/24
9. How do I Add Persistence Static Routes
All the above route will be lost after a system restart. To add permanent Static route, edit file /etc/sysconfig/network-scripts/route-eth0 (We are storing static route for (eth0) and add the following lines and save and exist. By default route-eth0 file will not be there, need to be created.
# vi /etc/sysconfig/network-scripts/route-eth0 10.10.20.0/24 via 192.168.50.100 dev eth010. How do I Add Default Gateway
Default gateway can be specified globally or for in interface-specific config file. Advantage of default gateway is If we have more than one NIC is present in the system. You can add default gateway on the fly as shown below command.
# ip route add default via 192.168.50.100