Ubuntu的設置

修改主機名

root@ubuntu1804:~# hostnamectl set-hostname ubuntu1804.magedu.org
root@ubuntu1804:~# cat /etc/hostname
ubuntu1804.magedu.org
root@ubuntu1804:~# hostname
ubuntu1804.magedu.org
root@ubuntu1804:~# echo $HOSTNAME
ubuntu1804
root@ubuntu1804:~# exit
logout
wang@ubuntu1804:~$ sudo -i
root@ubuntu1804:~# echo $HOSTNAME
ubuntu1804.magedu.org

網卡名稱

默認ubuntu的網卡名稱和 CentOS 7 相似,如:ens33,ens38等linux

修改網卡名稱爲傳統命名方式:ubuntu

#修改配置文件爲下面形式
root@ubuntu1804:~#vi /etc/default/grub
GRUB_CMDLINE_LINUX="net.ifnames=0"
#或者sed修改
root@ubuntu1804:~# sed -i.bak '/^GRUB_CMDLINE_LINUX=/s#"$#net.ifnames=0"#' 
/etc/default/grub
#生效新的grub.cfg文件
root@ubuntu1804:~# grub-mkconfig -o /boot/grub/grub.cfg 
#或者
root@ubuntu1804:~# update-grub
root@ubuntu1804:~# grep net.ifnames /boot/grub/grub.cfg
       linux /vmlinuz-4.15.0-96-generic root=UUID=51517b88-7e2b-4d4a-8c14-
fe1a48ba153c ro net.ifnames=0
       linux /vmlinuz-4.15.0-96-generic root=UUID=51517b88-7e2b-4d4a-
8c14-fe1a48ba153c ro net.ifnames=0
       linux /vmlinuz-4.15.0-96-generic root=UUID=51517b88-7e2b-4d4a-
8c14-fe1a48ba153c ro recovery nomodeset net.ifnames=0
       linux /vmlinuz-4.15.0-76-generic root=UUID=51517b88-7e2b-4d4a-
8c14-fe1a48ba153c ro net.ifnames=0
       linux /vmlinuz-4.15.0-76-generic root=UUID=51517b88-7e2b-4d4a-
8c14-fe1a48ba153c ro recovery nomodeset net.ifnames=0 #重啓生效
root@ubuntu1804:~# reboot

配置自動獲取**IP**

root@ubuntu1804:~# cat /etc/netplan/01-netcfg.yaml 
# This file describes the network interfaces available on your system
# For more information, see netplan(5).
network:
 version: 2
 renderer: networkd
 ethernets:
   eth0:
     dhcp4: yes

修改網卡配置文件後需執行命令生效:bash

root@ubuntu1804:~#netplan apply

靜態的IP配置

[root07:19 PMubuntu /etc/netplan]#pwd
/etc/netplan
[root07:10 PMubuntu /etc/netplan]#cat 02-eth1.yaml 
network:
  version: 2
  renderer: networkd
  ethernets:
    eth1:
      addresses: [192.168.8.10/24,10.0.0.10/8] 
      gateway4: 10.0.0.2
      nameservers:
        search: [magedu.com, magedu.org]
        addresses: [180.76.76.76, 8.8.8.8, 1.1.1.1]

查看DNS

root@ubuntu1804:~# systemd-resolve --status
相關文章
相關標籤/搜索