📜  centos ip (1)

📅  最后修改于: 2023-12-03 15:14:07.648000             🧑  作者: Mango

CentOS IP

CentOS is a popular Linux distribution used by many programmers and system administrators. In this tutorial, we will cover how to setup and configure IP addresses on a CentOS machine.

Checking Current IP Address

To check the current IP address of your CentOS machine, you can use the ip addr show command. Open up a terminal window and enter the following command:

$ ip addr show

This will output the IP address of your machine which will look something like this:

2: enp0s3: <UP,BROADCAST,MULTICAST,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
   link/ether 08:00:27:f4:5d:e9 brd ff:ff:ff:ff:ff:ff
   inet 192.168.1.10/24 brd 192.168.1.255 scope global dynamic enp0s3
      valid_lft 42278sec preferred_lft 42278sec
   inet6 fe80::a00:27ff:fef4:5de9/64 scope link
      valid_lft forever preferred_lft forever

In this example, the IP address of the machine is 192.168.1.10.

Configuring Static IP Address

By default, CentOS will obtain an IP address using DHCP. However, if you need to assign a specific static IP address to your machine, you can do so by editing the appropriate configuration file.

First, open up the /etc/sysconfig/network-scripts/ifcfg-enp0s3 configuration file in your favorite text editor. Make sure to replace enp0s3 with the name of the network interface on your machine. Then, add the following lines to the end of the file:

IPADDR={YOUR_IP_ADDRESS}
NETMASK={YOUR_NETMASK}
GATEWAY={YOUR_GATEWAY}
DNS1={YOUR_PRIMARY_DNS}
DNS2={YOUR_SECONDARY_DNS}

Replace the {YOUR_IP_ADDRESS}, {YOUR_NETMASK}, {YOUR_GATEWAY}, {YOUR_PRIMARY_DNS}, and {YOUR_SECONDARY_DNS} placeholders with the appropriate values for your network.

Save the configuration file and restart your network service by running the following command:

$ sudo systemctl restart network

Your CentOS machine should now be using the static IP address that you specified.

Conclusion

In this tutorial, we covered how to check the current IP address of a CentOS machine and how to configure a static IP address. Knowing how to manage IP addresses is an essential skill for any programmer or system administrator working with CentOS.