devops, host name resolution

Introduction

When using Linux, especially in a virtual environment, often devops may face with a necessity of accessing its host by the name, not by IP address. The reason is clear: once a DHCP server leases a new IP address, you have to change your configuration.

In case if these hosts use the same channel network you can configure SAMBA on Linux to make it work not only with Windows host names, but also resolve its own host name within the same network.

In this article we are going to answer the following questions:

  • How to access Windows host using its name from Linux host?
  • How to access Linux host using its name from Windows host?

Devops: Accessing Windows Host Name From Linux

In order to make Windows host names available from Linux follow these steps:

  1. Install a samba-winbind package – a Name Service Switch daemon for resolving names from NT servers:

    Debian / Ubuntu: apt-get -y install samba-winbind
    Centos / RedHat / Fedora: yum -y install samba-winbind

    You do not need to start or enable winbind service

  2. Check and modify Name Service Switch configuration in /etc/nsswitch.conf file: you need to find the hosts property key and check if it contains wins value: hosts: files dns wins
  3. Either disable or configure firewalld service:

    Disable:

    systemctl stop firewalld
    systemctl disable firewalld	
    

    Configure:

    firewall-cmd --zone=public --add-port=137/udp --permanent
    firewall-cmd --zone=public --add-port=137/tcp --permanent

Devops: Accessing Linux Host Name From Windows

In order to make Linux host names available from Windows you need a NetBIOS name server. It is already contained in a samba package – a server to provide SMB/CIFS services to clients. So, you need to do the following:

  1. Install a samba package:Debian / Ubuntu: apt-get -y install samba
    Centos / RedHat / Fedora: yum -y install samba

    You do not need to start or enable smb service

  2. Setup the netbios name for your host in /etc/samba/smb.conf file: you need to find the netbios name property, uncomment it if it is commented and set the value: netbios name = myhost
  3. Start and enable the nmb service:
    systemctl start nmb
    systemctl enable nmb
  4. Either disable or configure firewalld service:

    Disable:

    systemctl stop firewalld
    systemctl disable firewalld

    Configure:

    firewall-cmd --zone=public --add-port=137/udp --permanent
    firewall-cmd --zone=public --add-port=137/tcp --permanent

Enjoy your day and read more devops articles here!

Vladyslav Baidak - Scalified

Vladyslav Baidak

Backend Engineer at Scalified