Source From Here
Preface
In this post, we are going to review how we can assign Static IP Address, Static Route, Default Gateway etc. Assigning IP Address on demand using IP command.IFCONFIG command is deprecated and replaced by IP command in Linux. However, IFCONFIG command is still works and available for most of the Linux distributions.
How do i Configure Static IP Address Internet Protocol (IPv4)
To configure static IP Address, you need to update or edit network configuration file to assign an Static IP Address to a system. You must be superuser with su (switch user) command from terminal or command prompt.
For RHEL/CentOS/Fedora
Open and edit network configuration file for (eth0 or eth1) using your favorite editor. For example, to assigning IP Address to eth0 interface as follows.
For Ubuntu/Debian/Linux Mint
Assign Static IP Address to eth0 interface editing configuration file /etc/network/interfaces to make permanent changes as shown below.
Next, restart network services after entering all the details using the following command.
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.
Note: Unfortunately all these settings will be lost after a system restart.
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.
3. How to Remove an IP Address
The following command will remove an assigned IP address from the given interface (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.
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.
6. How do I Check Route Table?
Type the following command to check the routing table information of system.
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.
8. How to Remove Static Route
To remove assigned static route, simply type the following command.
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.
For RHEL/CentOS/Fedora
For Ubuntu/Debian/Linux Mint
Open the file /etc/network/interfaces and at the end add the persistence Static routes. IP Addresses may differ in your environment.
Next, restart network services after entering all the details using the following command.
10. 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.
Preface
In this post, we are going to review how we can assign Static IP Address, Static Route, Default Gateway etc. Assigning IP Address on demand using IP command.IFCONFIG command is deprecated and replaced by IP command in Linux. However, IFCONFIG command is still works and available for most of the Linux distributions.
How do i Configure Static IP Address Internet Protocol (IPv4)
To configure static IP Address, you need to update or edit network configuration file to assign an Static IP Address to a system. You must be superuser with su (switch user) command from terminal or command prompt.
For RHEL/CentOS/Fedora
Open and edit network configuration file for (eth0 or eth1) using your favorite editor. For example, to assigning IP Address to eth0 interface as follows.
For Ubuntu/Debian/Linux Mint
Assign Static IP Address to eth0 interface editing configuration file /etc/network/interfaces to make permanent changes as shown below.
- auto eth0
- iface eth0 inet static
- address 192.168.50.2
- netmask 255.255.255.0
- gateway 192.168.50.1
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.
Note: Unfortunately all these settings will be lost after a system restart.
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.
3. How to Remove an IP Address
The following command will remove an assigned IP address from the given interface (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.
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.
6. How do I Check Route Table?
Type the following command to check the routing table information of system.
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.
8. How to Remove Static Route
To remove assigned static route, simply type the following command.
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.
For RHEL/CentOS/Fedora
For Ubuntu/Debian/Linux Mint
Open the file /etc/network/interfaces and at the end add the persistence Static routes. IP Addresses may differ in your environment.
Next, restart network services after entering all the details using the following command.
10. 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.
沒有留言:
張貼留言