See the following code section: sudo ip addr add 192.168.1.10/24 dev enp1s0 Valid_lft forever preferred_lft ~]# Configuring Static IP through CLIĬonfiguring Static IP configuration from the command line is very simple, We will use ip addr commands to set the IP and other configurations. ~]# ip aġ: lo: mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000 Also, enp1s0 has 192.168.1.10 IP address and we will change this IP address to the above-mentioned IP address. enp1s0 is the only actual interface that is responsible for network packet transfer from or into the system. lo is loopback interface or local interface which have 127.0.0.1 IP address. Ip a command list all the interfaces, output list two interfaces in our environment lo and enp1s0.
So first let’s identify the name of our network interface which we want to configure, to check or list all the interfaces in CentOS use the following command. In CentOS interface name is typically start with en, in our case, we will assign the following network configuration to the enp1s0 interface (see the next section to know what all network devices are present in our environment).īefore assigning the above network configuration to our CentOS machine’s network interface we need to make sure that the interface is present there.
Similarly, like How to add a Static IP address in Ubuntu 20.04 server we will show two different strategies here one with CLI and which is not persistent and the other with NetworkManager or network-scripts which is persistent through even reboot. Therefore, in this article, we will configure static IP addresses in CentOS. Setting up networks in these systems is crucial. PEERDNS=no (then add DNS to /etc/resolv.We know as a system or network administrator we have to deal with different kinds of Operating systems and Linux OSes are majority in them. The above two methods can be applied similarly to a static IP address case. So there is no need to modify /etc/nf yourself. The DNS servers specified with DNS1/DNS2 directives will then automatically be added to /etc/nf when the interface is activated. That is: $ sudo vi /etc/sysconfig/network-scripts/ifcfg-eth0 $ sudo vi /etc/nfĪlternatively, you can specify DNS servers directly in the interface configuration file, instead of modifying /etc/nf yourself. $ sudo vi /etc/sysconfig/network-scripts/ifcfg-eth0 The configuration file for your network interface (e.g., eth0) looks like the following. So instead of using DHCP-provided DNS, you can specify any arbitrary DNS servers you want to use in /etc/nf. This option will prevent /etc/nf from being modified by a DHCP server. In this case, there are actually two ways to do it. If you disabled Network Manager, but use network service instead, you can use interface configuration files (e.g., /etc/sysconfig/network-scripts/ifcfg-eth0) to specify static DNS. Configure Static DNS in /etc/sysconfig/network-scripts/ifcfg. If you use a static IP address, simply enter your DNS servers in the DNS servers field. Then in the DNS servers field, enter a comma separate list of DNS servers to use (e.g., 8.8.8.8 and 8.8.4.4). In case of DHCP, choose Automatic (DHCP) addresses only method, so that your DHCP server cannot override your DNS setting.
If you are using Network Manager, you can configure static DNS as follows. Configure Static DNS with Network Manager On RHEL based systems, Network Manager is used to manage network interfaces by default, while you can always switch to network service. If you want to hard-code DNS servers to use on CentOS or Fedora, the method can differ, depending on whether you use Network Manager or network service. In general, how can I configure DNS servers statically on CentOS or Fedora? However, I want to use public DNS servers (e.g., Google DNS), not those assigned by a DHCP server. Question: On CentOS, I am getting an IP address assigned by DHCP.