Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I have a Debian server with 4 IP addresses. All IP addresses use the same hostname. Is it possible to give every single IP address its own unique hostname?

share|improve this question
3  
they already have different names, the hostname you are referring to is used to identify a host. a host can have multiple ip addresses with each ip address having different dns records –  Ulrich Dangel Jul 5 at 15:59
1  
Could you please describe the use case and your expectation? It's not very clear what you mean by hostname in your question as it typically refers to name of the host as seen by the user. It may also refer to the DNS names assigned to IP addresses via A/AAAA and PTR records. –  Pavel Šimerda Jul 5 at 20:13
    
If you want to use these hostnames to connect from another computer then you have to configure them in DNS or the remote computer's /etc/hosts file –  Creek Jul 6 at 14:05

2 Answers 2

you can use named service like bind to give each IP a domain name:

1- install BIND

on debian: https://wiki.debian.org/Bind9

2- configure a zone which includes the IPs and its hostnames:

$TTL    3600
@       IN      SOA     sid.example.com. root.example.com. (
               2007010401           ; Serial
                     3600           ; Refresh [1h]
                      600           ; Retry   [10m]
                    86400           ; Expire  [1d]
                      600 )         ; Negative Cache TTL [1h]
;
@       IN      NS      sid.example.com.
@       IN      MX      10 sid.example.com.

hostname1     IN      A       192.168.0.1
hostname2     IN      A       192.168.0.2
hostname3     IN      A       192.168.0.3
hostname4     IN      A       192.168.0.4
share|improve this answer
1  
Some purposes could be simply served using /etc/hosts. –  Pavel Šimerda Jul 5 at 20:19

Depending on the number of computers you are managing it is often much easier to just edit the host file on each system than it is to configure each computer to use a particular DNS server, especially if you don't have a dedicated Bind server for this task. Unix, Linux, Windows and Mac all use the exact same host files so it is easy to copy them around. Linux systems usually keep it in /etc/hosts like others have mentioned. You can then write a script to propagate these files to each of your systems if you need to. Here is an example hosts file:

###################################################################
## This is an example HOSTS file created by         
## www.bleepingcomputer.com.                     
##                               
## All entries in a HOSTS file must be in the format of:     
##                               
## ipaddress    hostname                     
##                               
## For example:                          
##                               
## 192.168.1.1  mycomputer.mydomain.com              
##                               
## Notice that you must have a whitespace between the IP address 
## and the hostname.  Also keep in mind that the hostname can    
## not contain any symbols like /,\,http://, etc.        
##                               
## As a last note, you can the # symbol to make comments.  Any   
## line that starts with the # symbol will not be parsed by      
## the operating system.  You can therefore use this # symbol    
## to make comments as seen below.               
##                               
## Example valid entries found below.                
###################################################################

# The localhost entry should be in every HOSTS file and is used
# to point back to yourself.

127.0.0.1   localhost

# My test server for the website

192.168.1.2 test.bleepingcomputer.com

#Blocking known malicious sites
127.0.0.1  admin.abcsearch.com
127.0.0.1  www3.abcsearch.com #[Browseraid]
127.0.0.1  www.abcsearch.com #[Restricted Zone site]

For your case you can just add one line for each IP. Also note that you can give multiple names to a single IP by separating them each by a space on the same line.

This change will be instant, you don't need to restart anything. You may need to refresh the DNS cache though if you've already tried to use the name.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.