It is common to configure server machines to have a static IP. This avoids having to rely on DNS resolution to find the server when its IP address changes, and it also allows you to associate the hostname to the server's static IP address on the machine to skip DNS resolution altogether, increasing network performance.
If your machine is currently connected to a DHCP server that dynamically assigns IP addresses, you can configure your machine to permanently use its current IP address. To do this, you can start by making note of the information for your current network connection, then using these parameters for a permanent IP address.
-
To obtain your machine's hostname, enter the following command:
$ hostname
Write down the output value.
-
To obtain the network domain, enter the following command:
$ hostname -d
Write down the output value.
-
To obtain your machine's default gateway and network device, enter the following command:
$ route
The output will look like this:
Destination Gateway Genmask Flags Metric Ref Use Iface 10.120.0.0 * <subnet mask> U 1 0 0 <device name> default <default gateway> 0.0.0.0 UG 0 0 0 <device name>
One of the rows will have default in the destination column. In this row, the name of the device in the Iface column is the name of your default network device. Write down the name of that device.
-
To obtain your machine's IP and subnet mask, enter the following command, replacing <device name> with the name of the device noted in the previous step:
$ nmcli -f all dev list iface <device name>
Information about the network interface will appear, in either one of the following formats:
GENERAL.DEVICE: <device name> GENERAL.TYPE: 802-3-ethernet GENERAL.DRIVER: tg3 GENERAL.HWADDR: <MAC address> GENERAL.STATE: connected CAPABILITIES.CARRIER-DETECT: yes CAPABILITIES.SPEED: 1000 Mb/s WIRED-PROPERTIES.CARRIER: on IP4-SETTINGS.ADDRESS: <IPv4 address> IP4-SETTINGS.PREFIX: <prefix> (<subnet mask>) IP4-SETTINGS.GATEWAY: <default gateway> IP4-DNS1.DNS: <DNS server address>
Write down the IPv4 address, the subnet mask, the default gateway as well as every DNS server address listed.
You can also obtain the IP address (inet addr) and network mask (Mask) of your device with the command:
$ ifconfig <device name>
-
To obtain your machine's hostname, enter the following command:
$ hostname
Write down the output value.
-
To obtain the network domain, enter the following command:
$ hostname -d
Write down the output value.
-
To obtain your machine's default gateway and network device, enter the following command:
$ route
The output will look like this:
Destination Gateway Genmask Flags Metric Ref Use Iface 10.120.0.0 * <subnet mask> U 1 0 0 <device name> default <default gateway> 0.0.0.0 UG 0 0 0 <device name>
One of the rows will have default in the destination column. In this row, the name of the device in the Iface column is the name of your default network device. Write down the name of that device.
-
To obtain your machine's IP and subnet mask, enter the following command, replacing <device name> with the name of the device noted in the previous step:
$ nmcli -p -f IP4 connection show <device name>
Information about the network interface will appear. The output will be in this format.
=============================================================================== Activate connection details (0568a4c4-092a-46e9-9f25-2295a1389d6e) =============================================================================== IP4.ADDRESS[1]: <IPv4 address>/<prefix> IP4.GATEWAY: <default gateway> IP4.DNS[1]: <DNS server address> IP4.DOMAIN[1]: <search domains>
Write down the IPv4 address, the default gateway address, the DNS server address(es) and the search domain(s).
To obtain your subnet mask, enter the following command, replacing <device name> with the name of the device noted in the previous step:
$ nmcli -p -f DHCP4 connection show <device name> | grep 'subnet_mask'
The output should look like this:
DHCP4.OPTION[3]: subnet_mask = <subnet mask>
Write down the subnet mask.
You can also obtain the IP address (inet) and network mask (netmask) of your device with the command:
$ ifconfig <device name>
-
Before you do this, make sure you have the following information for your machine:
- Name of default network device (ie: eth0, p3p1)
- Hostname
- Domain name
- Search domain(s)
- IPv4 address
- Network mask
- Default gateway address
- DNS server address(es)
-
Open your machine's network configuration file for editing:
$ sudo vi /etc/sysconfig/network
-
Configure the file as follows, replacing the bolded text with the appropriate values:
NETWORKING=yes HOSTNAME=<hostname>.<domain name>
-
Open your default network interface's configuration file for editing. This file will be named ifcg- followed by the name of the network interface you noted earlier. For example, if your network interface is named eth0, the configuration file will be named ifcfg-eth0:
$ sudo vi /etc/sysconfig/network-scripts/ifcfg-<device name>
-
Configure the file with the appropriate values for the following parameters. If a value is already declared for one of these parameters, replace it. If not, add it to the file:
DEVICE="<device name>" BOOTPROTO=static IPADDR=<IPv4 address> NETMASK=<network mask> GATEWAY=<default gateway> ONBOOT=yes
-
Open the DNS configuration file for editing:
$ sudo vi /etc/resolv.conf
-
Configure the file as follows, replacing the bolded text with the appropriate values:
search <search domain mames> nameserver <DNS server address>
NOTES- If you have several search domains, enter them all on the same line after search, separated by spaces.
- If you have several DNS servers, add one nameserver line for each address.
-
Restart the network service:
$ sudo service network restart
Comments
0 comments
Article is closed for comments.