网络配置文件:/etc/network/interfaces
每次修改完配置文件后,需要重启networking 服务。
$ sudo /etc/init.d/networking restart
网卡状态:
nmcli device status
cat /etc/issue
ip addr
ssh root@192.168.122.63
nmcli con show
netplan apply
brctl show
sudo systemctl restart NetworkManager
1. 配置DHCP
配置文件:/etc/network/interfaces
$ sudo vi /etc/network/interfaces
# The primary network interface – use DHCP to find our address auto eth0 iface eth0 inet dhcp |
2. 指定IP地址
$ sudo vi /etc/network/interfaces
# The primary network interface auto eth0 iface eth0 inet static address 192.168.3.90 gateway 192.168.3.1 netmask 255.255.255.0 network 192.168.3.0 broadcast 192.168.3.255 |
3. 设置第二IP地址或虚拟IP地址
$ sudo vi /etc/network/interfaces
auto eth0:1 iface eth0:1 inet static address 192.168.1.60 netmask 255.255.255.0 network x.x.x.x broadcast x.x.x.x gateway x.x.x.x |
4.设置静态路由(原文没有此段,引用整理自 http://gfrog.net/2008/01/config-file-in-debian-interfaces-1/)
auto eth0 iface eth0 inet static address 192.168.1.42 network 192.168.1.0 netmask 255.255.255.128 broadcast 192.168.1.0 up route add -net 192.168.1.128 netmask 255.255.255.128 gw 192.168.1.2 up route add default gw 192.168.1.200 down route del default gw 192.168.1.200 down route del -net 192.168.1.128 netmask 255.255.255.128 gw 192.168.1.2两行up route表示接口启用的时候,添加一条静态路由和一个缺省路由;两行down route表示接口禁用的时候,删掉这两条路由配置。 |
5. 设置主机名
1)
查看主机名
$ sudo /bin/hostname
设置主机名
$ sudo /bin/hostname newname
注销后再登录,新主机名将生效。但是当系统重启时,该设置将失效,系统将从 /etc/hostname 文件重新读取主机名。
2)
显示主机名:
$ sudo sysctl kernel.hostname
设置主机名:
$ sudo sysctl kernel.hostname=server2
注销后,新主机名生效。但是当系统重启时,该设置将失效,系统将从 /etc/hostname 文件重新读取主机名。
3)
如果要固定主机名,需要编辑 /etc/hostname 文件。
$ sudo vi /etc/hostname
4)
如果要使新的主机名立即生效(译者注:原文此段有误,以下是在ubuntu server 11.10上经过验证的指令格式和结果),执行:
$ sudo /etc/init.d/hostname start
[sudo] password for localadmin: Rather than invoking init scripts through /etc/init.d, use the service(8) utility, e.g. service hostname startSince the script you are attempting to invoke has been converted to an Upstart job, you may also use the start(8) utility, e.g. start hostname hostname stop/waiting |
6. 设置 DNS
这方面ubuntu与其他linux发行版没有区别。
可以编辑 /etc/hosts 文件指定固定的名称解析。
可以编辑 /etc/resolv.conf 指定DNS服务器地址,如下:
nameserver 192.168.3.2
7. 网络调试工具
这方面Ubuntu与其他linux发行版没有区别,比如:
ping
traceroute
ifconfig
route -n
netstat -nr
netstat -a
netstat -l
原文:http://www.debianadmin.com/ubuntu-networking-for-basic-and-advanced-users.html
把一个安装好的ubuntu server 虚拟机复制到另一台电脑,启动后网络接口 eth0 总是失败。
看看:
$ sudo ifquery –list lo eth0 |
试试:
$ sudo ifup eth0 Can not find device “eth0″ Failed to bring up eth0. |
查查:
$ cat /etc/network/interfaces # The primary network interface auto eth0 iface eth0 inet dhcp |
改改:
# The primary network interface auto eth0 iface eth0 inet static address … netmask … gateway … network … broadcast … |
再试试:
$ sudo ifup eth0 Can not find device “eth0″ Failed to bring up eth0. |