歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> Linux教程 >> 在UBUNTU命令行下自己手動配置網絡

在UBUNTU命令行下自己手動配置網絡

日期:2017/2/28 17:44:52   编辑:Linux教程
LINUX下的網絡配置命令是ifconfig類似於WINDOWS命令行中的ipconfig。可以使用ifconfig命令來配置並查看網絡接口的配置情況。
例如:
(1) 配置eth0的IP地址, 同時激活該設備。
#ifconfig eth0 192.168.1.10 netmask 255.255.255.0 up
(2) 配置eth0別名設備eth0:1的IP地址,並添加路由。
#ifconfig eth0 192.168.1.3
#route add –host 192.168.1.3 dev eth0:1
(3) 激活設備。
#ifconfig eth0 up
(4) 禁用設備。
#ifconfig eth0 down
(5) 查看指定的網絡接口的配置。
#ifconfig eth0
(6) 查看所有的網絡接口配置。
#ifconfig
2、 route
可以使用route命令來配置並查看內核路由表的配置情況。
例如:
(1) 添加到主機的路由。
#route add –host 192.168.1.2 dev eth0:0
#route add –host 10.20.30.148 gw 10.20.30.40
(2) 添加到網絡的路由。
#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
(3) 添加默認網關。
#route add default gw 192.168.1.1
(4) 查看內核路由表的配置。
#route
(5)刪除路由。
#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.1
對於1和2兩點可使用下面的語句實現:
Ifconfig eth0 172.16.19.71 netmask 255.255.255.0
Route 0.0.0.0 gw 172.16.19.254
Service network restart
Copyright © Linux教程網 All Rights Reserved