드레스룸 시스템행거 인테리어

반응형

linux hostname, hosts 파일 및 hosts.deny hosts.allow 알아보기

 

hostname 이란 시스템 네트워크 장치에 할당된 이름이다.

 

쉽게 다른 서버들에게 IP가 아닌 별칭으로 설정해 접근할 수 있다.

 

 

vmware 가상 서버 ( IP 192.168.6.144 ) centos 7.6

[root@localhost ~]# hostname
localhost.localdomain
[root@localhost ~]# hostnamectl set-hostname centos
[root@localhost ~]# hostname
centos
[root@localhost ~]# logout
Connection to 192.168.6.144 closed.
                                                                                                                                                                                                                ✔
─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
[2020-07-20 13:24.25]  ~
[.LAPTOP-OJ2LO4LK] ➤ ssh root@192.168.6.144
root@192.168.6.144's password:
Last login: Mon Jul 20 13:23:28 2020 from 192.168.6.1
[root@centos ~]#

 

hostnamectl 커맨드를 통해 hostname을 centos로 변경하였다.

 

변경된 hostname은 화면에 제대로 표기가 되려면 logout후 다시 login을 진행하게 되면 정상출력이 된다.

 

 

 

ubuntu 로컬 서버 ( IP 192.168.15.159 ) ubuntu 18.04

(base) root@ubuntu:~# hostname
ubuntu

 

기존의 test 하던 서버였기 때문에 hostname이 이미 들어간 상태이며 ubuntu 역시 centos와 마찬가지로 hostnamectl을

 

통한 hostname 변경이 가능하다.

 

 


centos

 

 

# vim /etc/hosts

127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.6.144   centos      ##### ADD
192.168.15.159  ubuntu      ##### ADD

 

기존의 hosts 파일 하단에 IP주소와 hostname을 기재하면 된다.

 

통신이 가능한 네트워크단에 있는 호스트의 IP Address와 hostname을 기재 하면 서로 통신이 가능하다.

 

그럼 hosts의 등록이 잘 되었는지 확인해 보자~!

 

[root@centos ~]# ping 192.168.15.159
PING 192.168.15.159 (192.168.15.159) 56(84) bytes of data.
64 bytes from 192.168.15.159: icmp_seq=1 ttl=128 time=1.72 ms
64 bytes from 192.168.15.159: icmp_seq=2 ttl=128 time=2.92 ms

--- 192.168.15.159 ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1002ms
rtt min/avg/max/mdev = 1.720/2.322/2.924/0.602 ms

[root@centos ~]# ping ubuntu
PING ubuntu (192.168.15.159) 56(84) bytes of data.
64 bytes from ubuntu (192.168.15.159): icmp_seq=1 ttl=128 time=2.90 ms
64 bytes from ubuntu (192.168.15.159): icmp_seq=2 ttl=128 time=1.90 ms
64 bytes from ubuntu (192.168.15.159): icmp_seq=3 ttl=128 time=2.48 ms

--- ubuntu ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2002ms
rtt min/avg/max/mdev = 1.903/2.430/2.903/0.410 ms

[root@centos ~]# ssh ubuntu
>>>>>>>>>>>>> Test GPU Server <<<<<<<<<<<<<<
Ubuntu 18.04.1 LTS

ADMIN : ckkim
kyumdoctor.tistory.com
1985ck@naver.com

IP : 192.168.15.159
TF : 1.13.1

root@ubuntu's password:
Welcome to Ubuntu 18.04.1 LTS (GNU/Linux 4.15.0-29-generic x86_64)

 * Documentation:  https://help.ubuntu.com
 * Management:     https://landscape.canonical.com
 * Support:        https://ubuntu.com/advantage

  System information as of Mon Jul 20 01:00:03 EDT 2020

  System load:  0.78             Processes:              339
  Usage of /:   2.8% of 1.72TB   Users logged in:        1
  Memory usage: 3%               IP address for eno1:    192.168.15.159
  Swap usage:   0%               IP address for docker0: 172.17.0.1

 * "If you've been waiting for the perfect Kubernetes dev solution for
   macOS, the wait is over. Learn how to install Microk8s on macOS."

   https://www.techrepublic.com/article/how-to-install-microk8s-on-macos/

 * Canonical Livepatch is available for installation.
   - Reduce system reboots and improve kernel security. Activate at:
     https://ubuntu.com/livepatch

225 packages can be updated.
135 updates are security updates.


Last login: Mon Jul 20 00:59:42 2020 from 192.168.15.35
            .-/+oossssoo+/-.               root@ubuntu
        `:+ssssssssssssssssss+:`           -----------
      -+ssssssssssssssssssyyssss+-         OS: Ubuntu 18.04.1 LTS x86_64
    .ossssssssssssssssssdMMMNysssso.       Host: X10DRi 123456789
   /ssssssssssshdmmNNmmyNMMMMhssssss/      Kernel: 4.15.0-29-generic
  +ssssssssshmydMMMMMMMNddddyssssssss+     Uptime: 4 mins
 /sssssssshNMMMyhhyyyyhmNMMMNhssssssss/    Packages: 1958
.ssssssssdMMMNhsssssssssshNMMMdssssssss.   Shell: bash 4.4.19
+sssshhhyNMMNyssssssssssssyNMMMysssssss+   Terminal: /dev/pts/1
ossyNMMMNyMMhsssssssssssssshmmmhssssssso   CPU: Intel Xeon E5-2637 v3 (16) @ 3.700GHz
ossyNMMMNyMMhsssssssssssssshmmmhssssssso   GPU: ASPEED Technology, Inc. ASPEED Graphics Family
+sssshhhyNMMNyssssssssssssyNMMMysssssss+   GPU: NVIDIA GeForce RTX 2080 Ti
.ssssssssdMMMNhsssssssssshNMMMdssssssss.   Memory: 976MiB / 32054MiB
 /sssssssshNMMMyhhyyyyhdNMMMNhssssssss/
  +sssssssssdmydMMMMMMMMddddyssssssss+
   /ssssssssssshdmNNNNmyNMMMMhssssss/
    .ossssssssssssssssssdMMMNysssso.
      -+sssssssssssssssssyyyssss+-
        `:+ssssssssssssssssss+:`
            .-/+oossssoo+/-.





root@ubuntu:~#

 

IP주소와 호스트네임으로 ping이 잘 나간다.

 

ssh 접속 또한 잘된다.

 

이다음으로는 hosts.allow 파일과 hosts.deny 파일의 역할에 대해 알아보자

 

hosts.allow 호스트 접속 허용 설정
hosts.deny 호스트 접속 차단 설정

 

 

ubuntu

 

root@ubuntu:~# vim /etc/hosts.allow
# /etc/hosts.allow: list of hosts that are allowed to access the system.
#                   See the manual pages hosts_access(5) and hosts_options(5).
#
# Example:    ALL: LOCAL @some_netgroup
#             ALL: .foobar.edu EXCEPT terminalserver.foobar.edu
#
# If you're going to protect the portmapper use the name "rpcbind" for the
# daemon name. See rpcbind(8) and rpc.mountd(8) for further information.
#

sshd    : 192.168.15.35

 

사용하는 방법은 여러 가지가 있지만 sshd에 특정 IP에게만 접근을 허용하게 하려면 위와 같이

 

sshd : 허용할 IP를 넣고

 

 

root@ubuntu:~# vim /etc/hosts.deny

# /etc/hosts.deny: list of hosts that are _not_ allowed to access the system.
#                  See the manual pages hosts_access(5) and hosts_options(5).
#
# Example:    ALL: some.host.name, .some.domain
#             ALL EXCEPT in.fingerd: other.host.name, .other.domain
#
# If you're going to protect the portmapper use the name "rpcbind" for the
# daemon name. See rpcbind(8) and rpc.mountd(8) for further information.
#
# The PARANOID wildcard matches any host whose name does not match its
# address.
#
# You may wish to enable this to ensure any programs that don't
# validate looked up hostnames still leave understandable logs. In past
# versions of Debian this has been the default.
# ALL: PARANOID


ALL:ALL

 

 

위와 같이  모든 것을 차단하게 되면 다른 PC에서 원격 접속을 시도할 경우 아래와 같은 메시지가 나오면서

 

접속을 할 수 없게 된다.

 

[Jo.DESKTOP-4KNSEQ2] ➤ ssh root@192.168.15.159
ssh_exchange_identification: read: Connection reset by peer

 

 

반응형

이 글을 공유합시다

facebook twitter kakaoTalk kakaostory naver band