关于我从liunx到ubuntu一路摸索过来总结的一些知识..
17.10以前版本
文件路径:/etc/sysconfig/network-scripts/ifcfg-eth0(你的网卡),设置网卡IP地址(也可以配置网关和DNS)
# 静态分配的配置方法:
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).
# The loopback network interface
auto lo
iface lo inet loopback
# The primary network interface
auto ens33
iface ens33 inet static
address 192.168.1.8 # IP地址
netmask 255.255.255.0 # 子网掩码
gateway 192.168.1.1 # 网关
broadcast 192.168.1.255 # 广播地址 在IP中,如果最后一改数字时255,那一定是广播地址(可忽略)
# 修改网卡的硬件地址:
ifconfig ens33 hw ether 00:0c:29:f0:cf:f9 #(可忽略)
DEVICE="eth0"
TYPE=Ethernet
BOOTPROTO=static
HWADDR=00:0C:29:4C:84:AB
IPADDR=192.168.1.8
NETMASK=255.255.255.0
GATEWAY=192.168.1.1
DEFROUTE="yes"
IPV4_FAILURE_FATAL="yes"
IPV6INIT=no
NAME="System eth0"
NM_CONTROLLED=yes
ONBOOT=yes
PEERDNS=yes
PEERROUTES="yes"
UUID="5fb06bd0-0bb0-7ffb-45f1-d6edd65f3e03"
USERCTL=no
DNS1=202.106.0.20
DNS2=192.168.1.1
(2)/etc/sysconfig/network,设置网关
NETWORKING=yes
HOSTNAME=localhost.localdomain
GATEWAY=192.168.1.1
(3)/etc/resolv.conf,设置DNS
nameserver=202.106.0.20
nameserver=192.168.1.1
search localdomain
修改网络配置 17.10以后版本
文件路径:/etc/netplan/00-installer-config.yaml
可以多种格式配置
# This is the network config written by 'subiquity'
network:
ethernets:
ens33: #配置的网卡的名称
addresses: [192.168.31.215/24] #配置的静态ip地址和掩码
dhcp4: no #关闭DHCP,如果需要打开DHCP则写yes
optional: true
gateway4: 192.168.31.1 #网关地址
nameservers:
addresses: [192.168.31.1,114.114.114.114] #DNS服务器地址,多个DNS服务器地址需要用英文逗号分隔开
version: 2
renderer: networkd #指定后端采用systemd-networkd或者Network Manager,可不填写则默认使用systemd-workd
routes: #默认路由 自己设置
- to: 172.18.0.0/16
via: 172.18.105.1
# This is the network config written by 'subiquity'
network:
version: 2
ethernets:
ens33: #网卡名称
dhcp4: no
addresses:
- 192.168.1.12/24 #ip
optional: true
gateway4: 192.168.1.1 #网关
nameservers:
addresses:
- 114.114.114.114 #dns1
- 255.255.255.255 #dns2
ens38:
dhcp4: no
addresses: [192.168.11.13/24]
optional: true
gateway4: 192.168.1.1
nameservers:
addresses:
- 114.114.114.114
- 255.255.255.255