使用ifconfig命令
语法格式:
ifconfig :不加任何选项表示只显示接口为up状态的接口信息
Ifconfig -a:表示显示所有接口的接口信息,不管该接口是up还是down都显示
Ifconfig interface [ip/netmask] [up|down]表示为该接口配置ip和掩码,并启动或关闭该接口
例子:ifconfig eth0:20 192.10.1.12 netmask 255.255.255.0 up
使用route命令
[root@linux ~]# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
192.168.10.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
169.254.0.0 0.0.0.0 255.255.0.0 U 0 0 0 eth0
0.0.0.0 192.168.10.30 0.0.0.0 UG 0 0 0 eth0
Flags:总共有多个旗标,代表的意义如下:
U (route is up):该路由是启动的;
H (target is a host):目标是一部主机 (IP) 而非网域;
G (use gateway):需要透过外部的主机 (gateway) 来转递封包;
R (reinstate route for dynamic routing):使用动态路由时,恢复路由资讯的旗标;
D (dynamically installed by daemon or redirect):已经由服务或转 port 功能设定为动态路由
M (modified from routing daemon or redirect):路由已经被修改了;
! (reject route):这个路由将不会被接受(用来抵挡不安全的网域!)
A (installed by addrconf)
route add default gw 192.168.10.30
# 增加预设路由的方法!请注意,只有一个预设路由
route add -net 10.20.30.48 netmask 255.255.255.248 gw 10.20.30.41
#添加10.20.30.48的网络
route del -net 10.20.30.48 netmask 255.255.255.248 gw 10.20.30.41
#删除路由
route del -net 224.0.0.0 netmask 240.0.0.0 reject