1. 程式人生 > >Linux修改主機名,DNS客戶端配置

Linux修改主機名,DNS客戶端配置

Linux修改主機名,DNS客戶端配置

修改主機名

  • 在Linux 7以前用hostname命令修改
//臨時修改主機名
[[email protected] ~]# hostname "lishengshengTest"
//如果需要永久修改主機名,需要同時修改/etc/hosts和/etc/sysconfig/network的相關內容。

  • 在Linux 7版本後我們用hostnamectl命令
//檢視主機狀態資訊
[[email protected] ~]# hostnamectl 
set-chassis     set-deployment  set-hostname    set-icon-name   status          
[
[email protected]
~]# // 下面命令永久修改了主機名 [[email protected] ~]# hostnamectl set-hostname lishengsheng.com

DNS客戶端配置

  • /etc/hosts檔案,加快域名解析,方便小型區域網使用者使用內部裝置

假設公司有A、B兩臺主機,B主機ip為192.168.1.6,為了方便訪問B主機,可以在A主機的/etc/hosts檔案中新增一條記錄


[[email protected] ~]# cat /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.1.6 hostCentOS7
[
[email protected]
~]# ping hostCentOS7 PING hostCentOS7 (192.168.1.6) 56(84) bytes of data. 64 bytes from hostCentOS7 (192.168.1.6): icmp_seq=1 ttl=64 time=0.474 ms ........

缺點僅能為有限的主機記錄,無法將所有已知的主機名新增記錄到hosts檔案中

DNS是全網際網路上主機名及其ip對應關係的資料庫,配置檔案/etc/resolv.conf。其檔案負責dns分發到個主機上

  • hosts和nslookup命令是用來查詢DNS記錄的,如果使用域名做引數,則返回該域名的ip
[[email protected] ~]# host baidu.com
baidu.com has address 220.181.57.216
baidu.com has address 123.125.115.110
baidu.com mail is handled by 20 mx50.baidu.com.
baidu.com mail is handled by 20 jpmx.baidu.com.
baidu.com mail is handled by 20 mx1.baidu.com.
baidu.com mail is handled by 15 mx.n.shifen.com.
baidu.com mail is handled by 10 mx.maillb.baidu.com.
[[email protected] ~]# 
//nslookup命令
[[email protected] ~]# nslookup baidu.com
Server:		192.168.1.1
Address:	192.168.1.1#53

Non-authoritative answer:
Name:	baidu.com
Address: 220.181.57.216
Name:	baidu.com
Address: 123.125.115.110

[[email protected] ~]# 
  • traceroute 命令是用來路由跟蹤的,檢測網路故障出現在ISP運營商或是對端服務無法響應

  • ss -lntup命名查詢所有監聽的服務(直接統計,快),netstat -lntup命令是看所有的(遍歷查詢,慢)

- 常見埠
http    80/tcp
https   443/tcp
ssh     22/etcp
ftp     20,21/tcp
mysql   3306/tcp
redis   6379/tcp
rsync   873/tcp