ubuntu18.04修改静态IP地址
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ubuntu18.04修改静态IP地址相关的知识,希望对你有一定的参考价值。
修改网卡名称查看原网卡名称为ens33
[[email protected] ~]#ifconfig
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,修改内核参数
[[email protected] ~]#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配置文件
[[email protected] ~]#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
重启系统再次查看网卡名称
[[email protected] ~]#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地址
编辑配置文件
[[email protected] ~]#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]
使配置文件生效
[[email protected] ~]#netplan apply
[[email protected] ~]#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地址
[[email protected] ~]#vim /etc/systemd/resolved.conf
#取消注释,并且加入DNSIP地址
[Resolve]
DNS=8.8.8.8
#FallbackDNS=
#Domains=
#LLMNR=no
#MulticastDNS=no
#DNSSEC=no
#Cache=yes
#DNSStubListener=yes
以上是关于ubuntu18.04修改静态IP地址的主要内容,如果未能解决你的问题,请参考以下文章