ubuntu18.04修改靜態IP地址

修改網卡名稱

查看原網卡名稱爲ens33
[root@master ~]#ifconfiglinux

ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.8.234  netmask 255.255.255.0  broadcast 192.168.8.255
        inet6 fe80::20c:29ff:fe36:658a  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:36:65:8a  txqueuelen 1000  (Ethernet)
        RX packets 280745  bytes 342084244 (342.0 MB)
        RX errors 378  dropped 0  overruns 0  frame 0
        TX packets 128466  bytes 22465197 (22.4 MB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
        device interrupt 19  base 0x2000

修改網卡名稱爲eth0,修改內核參數ios

[root@master ~]#vim /etc/default/grub 
GRUB_DEFAULT=0
GRUB_TIMEOUT_STYLE=hidden
GRUB_TIMEOUT=2
GRUB_DISTRIBUTOR=`lsb_release -i -s 2> /dev/null || echo Debian`
GRUB_CMDLINE_LINUX_DEFAULT=""
#在引號之間增長以下幾行
GRUB_CMDLINE_LINUX="net.ifnames=0 biosdevname=0"

生成grub配置文件vim

[root@master ~]#grub-mkconfig -o /boot/grub/grub.cfg 
Sourcing file `/etc/default/grub'
Generating grub configuration file ...
Found linux image: /boot/vmlinuz-4.15.0-29-generic
Found initrd image: /boot/initrd.img-4.15.0-29-generic
done

重啓系統再次查看網卡名稱app

[root@master ~]#ifconfig
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.8.234  netmask 255.255.255.0  broadcast 192.168.8.255
        inet6 fe80::20c:29ff:fe36:658a  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:36:65:8a  txqueuelen 1000  (Ethernet)
        RX packets 280745  bytes 342084244 (342.0 MB)
        RX errors 378  dropped 0  overruns 0  frame 0
        TX packets 128466  bytes 22465197 (22.4 MB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
        device interrupt 19  base 0x2000

修改IP地址爲靜態IP地址

編輯配置文件ide

[root@master ~]#vim /etc/netplan/01-netcfg.yaml 
network:
  version: 2
  renderer: networkd
  ethernets:
    #網卡名稱
    eth0:
       addresses: [192.168.8.234/24]
       gateway4: 192.168.8.2
       nameservers:
           addresses: [8.8.8.8]

使配置文件生效code

[root@master ~]#netplan apply
[root@master ~]#ifconfig
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.8.234  netmask 255.255.255.0  broadcast 192.168.8.255
        inet6 fe80::20c:29ff:fe36:658a  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:36:65:8a  txqueuelen 1000  (Ethernet)
        RX packets 280745  bytes 342084244 (342.0 MB)
        RX errors 378  dropped 0  overruns 0  frame 0
        TX packets 128466  bytes 22465197 (22.4 MB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
        device interrupt 19  base 0x2000

永久修改DNS地址

[root@master ~]#vim /etc/systemd/resolved.conf 
#取消註釋,而且加入DNSIP地址
[Resolve]
DNS=8.8.8.8
#FallbackDNS=
#Domains=
#LLMNR=no
#MulticastDNS=no
#DNSSEC=no
#Cache=yes
#DNSStubListener=yes
相關文章
相關標籤/搜索