在使用Ubuntu时经常会遇到网络设置问题一般情况只需在桌面上进行设置即可。但有时也会遇到没有桌面、无法使用桌面或不方便使用桌面的情况这时就只能使用命令行来进行设置本文介绍几个用于设置Ubuntu网络的命令。1. ifconfig配置eth0的IP地址同时激活该设备ifconfig eth0 192.168.1.10 netmask 255.255.255.0 up配置eth0别名设备eth0的IP地址ifconfig eth0 192.168.1.3激活设备ifconfig eth0 up禁用设备fconfig eth0 down查看指定的网络接口的配置。ifconfig eth0查看所有的网络接口配置。ifconfig2. route可以使用route命令来配置并查看内核路由表的配置情况。添加到主机的路由route add –host 192.168.1.2 dev eth0:0 route add –host 10.20.30.148 gw 10.20.30.40添加到网络的路由route add –net 10.20.30.40 netmask 255.255.255.248 eth0 route add –net 10.20.30.48 netmask 255.255.255.248 gw 10.20.30.41 route add –net 192.168.1.0/24 eth1添加默认网关route add default gw 192.168.1.1查看内核路由表的配置route删除路由route del –host 192.168.1.2 dev eth0:0 route del –host 10.20.30.148 gw 10.20.30.40 route del –net 10.20.30.40 netmask 255.255.255.248 eth0 route del –net 10.20.30.48 netmask 255.255.255.248 gw 10.20.30.41 route del –net 192.168.1.0/24 eth1 route del default gw 192.168.1.13. netstat可以使用netstat命令来显示网络状态信息。显示网络接口状态信息netstat –i显示所有监控中的服务器的Socket和正使用Socket的程序信息netstat –lpe显示内核路由表信息netstat –r netstat –nr显示TCP/UDP传输协议的连接状态netstat –t netstat –u4. hostname查看主机名# 直接运行 hostname # 或者 cat /etc/hostname修改主机名hostnamectl set-hostname xxx参考文献https://www.cnblogs.com/zxouxuewei/p/4974178.htmlUbuntu 网络配置方法 - 背对背依靠 - 博客园