Changing the Host name and IP address of a Linux CentOS server

by | Oct 24, 2021 | Technical Help

This article explains how to change the hostname and IP address of a Linux CentOS 7 server.

There are two basic facts about subnets that are in play when making these particular changes:

  • The hostname is the name a computer (or server) goes by on the network. Each computer on a particular network must be named differently. In other words, there can only be one unique hostname on a subnet. For example, a typical home network might be addressed as 192.0.0.0 through 192,0.0.255. If a computer had a hostname of susan.mydomain.com another computer named that same name would create a network conflict.
  • Each computer on a particular network must reside at a different IP address. In other words, there can only be one server at any given unique IP address on a subnet. In the same example network above, only one computer on that network could exist at any given IP address on that network. If you were to add another computer to that same IP address by setting that already used IP address in its network interface card, an error would occur.

In this scenario, I needed to replace an existing server with a newer server. There was terabytes of backed up information on that existing server. Those backups needed to be moved to other servers prior to rebuilding and upgrading the box. To compound the situation, the file migration would need to be done in the background to avoid service degradation on the subnet. Such a move was estimated to take as long as a two months.

How to change the Host name

Step 1: Check Existing Hostname

It is prudent to check what your current hostname is. Typing the following command in the console will show you:

hostnamectl

The static hostname should be displayed, as well as other information about your network configuration and operating system.

Step 2: Set a New Static Hostname

As CentOS 7 only allows Fully Qualified Domain Names (FQDNs), double-check the hostname you plan to use.

Acceptable values can include these:

  • Lower-case letters a to z
  • Numbers 0 to 9
  • Periods and hyphens
  • Hostnames must be between 2 and 63 characters
  • Hostnames must start and end with a number or letter
  • Type in the following command in the terminal:
hostnamectl set-hostname serverhost.exampledomain.com

Step 3: Check the Hostname

Next, verify the hostname by using the following command again:

hostnamectl

The console should display the new hostname.

Step 4: Edit the /etc/hosts File

In my example here, I am using nano, which happens to be my favorite Linux text editor. Start by opening the hosts file in nano by typing:

nano /etc/hosts

In the text editor, look for the line that begins with 127.0.0.1 (the IP address that refers to the system you are working on). It should read:

127.0.0.1 localhost localhost.localdomain localhost 4 localhost4.localdomain4 old.hostname

Change the existing entry (old.hostname in the example) to your new server hostname (serverhost.exampledomain.com was used in the example in step 2 above) and spell it the same as you did in Step 2.

Save the file and exit.

Step 5: Reboot and Check CentOS 7 machine hostname

Restart the computer (or server). Again, open a console window, and run:

hostnamectl

It should display the new hostname.

You can also use your text editor again to verify your /etc/hostsfile. It should still have the new hostname listed.

How to change the IP address

Step 1: Find Your Network Configuration File

Go to the /etc/sysconfig/network-scripts directory

Locate the configuration file of your interface (for example, mine showed ifcfg-eno1, ifcfg-eno1:0, and ifcfg-eno2).

Step 2: Edit Your Network Configuration File

Enter the following command:

nano /etc/sysconfig/network-scripts/ifcfg-eno1

Change the appropriate parts in the file.

ONBOOT=yes
BOOTPROTO=static
IP_ADDR=1.1.1.1 (Fill in your actual IP Address)
NETMASK=255.255.255.255 (Fill in your actual netmask here)

In the configuration file NM_CONTROLLED=no indicates that this interface will be set up using this configuration file, instead of being managed by Network Manager service. ONBOOT=yes tells the system to bring up the interface during boot.

Save your changes.

Step 3: Restart Network

Restart your network by entering the command:

service network restart

or

reboot

Your new static IP Address should be functioning now.

If it does not work, repeat the same steps again but this time set BOOTPROTO=none.

 

CLICK HERE to find your domain name!   CLICK HERE to transfer your domain name!

Archives

Tags

24 hour (1) Accessibility (2) Accounting (1) Advertising (16) AdWare (1) Alex Johnson (2) Alignment (1) Android (2) Anti-Virus (1) Antivirus (1) Antrim Computer Repair and Service (3) APC Back-UPS (1) Appearance (2) Apple Mail (4) Apple Mobile Mail (2) Attachments (1) Audit (1) Authorized (1) Autoresponder (5) Availability (1) Backups (1) Badges (3) Bank Account (1) Bank Statement (1) Battery Backup (2) Better Business Bureau (3) Bob Hill (1) Bookkeeper (1) Branding (8) Budget (2) Business (27) Business Management (1) Catalog (1) Categories (1) Charles Oropallo (1) CharlesWorks (42) Cherryl Jensen (1) Chrome (1) CleanTalk (1) Cloud (1) Code (2) Communicating (1) Competition (1) Computer (2) Computer Cache (1) Computer Hardware (1) Computer Security (2) Constant Contact (1) Consultation (1) Contact Information (2) Content (1) Content Management (37) Content Management System (1) Copiers (1) Copy Machine (1) Coronavirus (2) Courteous (1) COVID-19 (3) Credibility (9) Credit Card (1) Credit Card Processing (1) CSS (9) Customer Service (2) Database (1) Debian (1) Design (47) Design Expertise (1) Desktop (1) Dialup (1) DirectAdmin (4) Directions (1) DIVI (7) DNS (2) Do-it-Yourself (1) Documentation (1) Domains (18) Domain Transfers (5) E-Commerce (1) ecommerce (1) Elementor (1) Email (65) Email Lists (4) Email Management (4) Email marketing (4) Etiquette (3) Eudora 6 (1) Exchange (1) Expanding (1) Facebook (2) Financial (1) Finish (1) Firefox (1) Fonts (1) Forms (2) Forms Protection (1) Fraud (2) Galaxy S4 (1) General Info (1) Gmail (1) GoDaddy (1) Google (1) Google Adwords Certified Partner (1) Google Chrome (2) Groups (1) Happy Holidays (1) Hardware Help (1) Hill Specialty Networks (1) Hosting (1) Images (1) IMAP (1) include (1) Infected (1) Information (35) insert pages (1) Internet Browsing Errors (1) Internet Consultant (1) Internet Explorer (1) Joomla! (1) Keywords (2) Laptop (1) Legibility (1) Linux (12) Logging on (1) Macintosh (1) Mail 6.0 (1) Mail 2011 (2) Make-Over (1) Malicious (1) Malware (1) Marketing (8) Matt Burke (3) MDaemon (3) MelbourneIT (2) menu (1) Merchant (1) meta (1) Microsoft (1) Microsoft Edge (1) Microsoft Hosted Exchange (5) Microsoft Live (2) Mobile Email Setup (1) Monadnock Region (1) Mozilla Firefox (2) MySQL (1) Nathan Wesley (1) Netscape (1) Netscape Messenger (1) Office Copiers (1) OfficeLive (1) Online (1) Outlook (9) Outlook 2010 (2) Outlook Express (1) PayPal (1) Pay Per Click (2) PC (1) Personal (1) Peter Harris (1) Peter Harris Creative (1) Phishing (2) PHP (3) pixel (1) plugins (1) Pop Email (1) Popularity (1) Portfolio (1) Power Grid Failure (1) PPC (1) Prevent Fraud (1) Privacy (1) Private (1) Product (6) products (1) Professional (6) Projects (2) Protect (1) Protection (1) QR codes (1) Quality (2) QuickBooks (1) Reconciliation (1) Reduce Risk (1) Register (1) Reliability (2) Renew (1) Reseller (2) Resolution (1) Restrict User Access (1) Results (1) Review (2) Risk (1) Robin Snow (1) Roundcube (1) Safe (1) Samsung (2) Scam (16) Scammer (16) Search (1) Search and Replace (1) Search Engine Optimization (SEO) (21) Security (27) Security Risk (1) Selling (1) Servers (2) Service (11) Shopping Cart (1) Site (1) SmarterMail (9) Social Engineering (1) Social Networking (1) Software (1) solar flares (1) Solutions for Today (1) Spam (1) Spam Filtering (16) Spammer (1) Spyware (2) SquirrelMail (1) SSL (8) Statistics (2) Stats (2) Stone Pond Technology (1) Storage (1) Support (1) Tablet (1) Target Market (1) Technical Help (1) Testimonials (9) The CW Corner (1) Thom Little (1) Thom Little Associates (1) Thunderbird (3) Thunderbird 10 (2) TLD (1) Topic (1) Top Level Domains (3) Transaction (2) Transfer Data (1) Transfer Funds (1) Typography (1) Update (2) Uploading (1) UPS System (2) Up to Date (1) Virtualmin (1) Virus (2) Viruses (1) Vista (1) Web (1) Web-Over (1) Web Development (100) Web Hoster (1) Web Hosting (2) Web Hosting Company (1) Webmail (8) Web Mail (1) Webmaster (10) Webmin (1) Web Presence (28) Website (113) Website Development (1) websites (2) Web Stats (1) Web terms (1) Web Writing (1) Windows 7 (2) Windows Mail (6) Windows XP (1) WooCommerce (5) WordPress (89) WordPress Updates (1) Working Remote (2) Writing (1) YouTube (1)
Protected by CleanTalk Anti-Spam