码迷,mamicode.com
首页 > 系统相关 > 详细

linux网络配置命令 ifconfig 、route 、ip 、ip route

时间:2016-03-30 18:02:35      阅读:444      评论:0      收藏:0      [点我收藏+]

标签:ip   ip link   ip route ifconfig route   

ifconfig

route

ip

ip route


一、ifconfig 命令(查看或配置Ip)

1、查看网络连接

# ifconfig  \\ 显示所有活动连接,不包令禁用的设备

   或

 # ifconfig -a  \\ 显示所有活动及非活动的连接

显示指定接口的连接

# ifconfig eth1

2、配置ip地址

# ifconfig eth1 192.168.0.1 netmask 255.255.255.

# ifconfig eth1 192.168.0.1/24

3、启用或禁用接口

# ifconfig eth1 down|up
或
# ifdown eth1  \\ 禁用接口
# ifup eht1  \\启用接口


二、route命令(查看或配置路由)

1、查看路由,使用-n可以以数字格式查看显示路由避免反解主机名,造成查询过慢。

# route -n
Destination     Gateway         Genmask          Flags  Metric  Ref      Use Iface
192.168.0.0     0.0.0.0         255.255.255.0     U       0      0        0 eth1
目标       下一跳地址       掩码      标志位  跳跃点  ref  使用的哪个接口


2、添加路由

(a)、网络路由

# route add -net 192.168.1.0/24 gw 172.16.1.106

(b)、主机路由

# route add -host 192.168.1.110 gw 172.16.1.106

(c)、默认路由

# route add default gw 172.16.1.106
或
# route add -net 0.0.0.0 gw 172.16.1.106

查看这三条新创建的

Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
192.168.1.110   172.16.1.106    255.255.255.255 UGH   0      0        0 eth0
192.168.1.0     172.16.1.106    255.255.255.0   UG    0      0        0 eth0
0.0.0.0         172.16.1.106    0.0.0.0         UG    0      0        0 eth0


3、删除路由

# route del -host 192.168.1.110
# route del -net 192.168.1.0/24


三、DNS配置

只能通过配置文件:/etc/resolv.conf来修改内容如下

; generated by /sbin/dhclient-script
search localdomain feng.com   \\ 搜索域
nameserver 172.16.0.2    \\ DNS域名服务器

一行一个DNS,最多配置三个DNS


************************************************************************************

随着系统的发展以上两种命令,会慢慢的被如下两个命令替换.

ifconfig = ip

route = ip route


ip命令

1、ip link(查看网络连接或启用禁用网卡)

(a)、查看网络连接

 # ip link show [Interace]  \\接口可省,省略后会显示所有连接

(b)、启用禁用接口及关闭启用多播

ip link set Interface [up|down] [multicast on|off]


2、ip addr(ip地址管理)

配置Ip

格式:ip addr add dev Interface Address [label Interface_alias]

(a)、给eth1配置一个IP或多个IP

# ip addr add dev eth1 192.168.1.118/24

(b)、给eth1的别名eth1:0配置一个Ip

# ip addr add dev eth1 192.168.0.12/24 label eth1:0

查看配置的Ip

# ip addr show eth1  \\ 查看配置好的ip,此命令配置的ip不能使用ifconfig来查看
3: eth1: <BROADCAST,MULTICAST> mtu 1500 qdisc pfifo_fast state DOWN qlen 1000
    link/ether 00:0c:29:42:91:29 brd ff:ff:ff:ff:ff:ff
    inet 192.168.1.118/24 scope global eth1
    inet 192.168.0.12/24 scope global eth1:0

删除配置的ip

# ip addr del dev eth1 192.168.1.118/24


清除配置

# ip addr flush Interface [to Net_Address] 

# ip addr flush eth1  \\ 不带任何参数可以清除该网卡的所有IP配置


ip addr flush eth0 to 192.168.0.0/24  \\ 只要是和192.168.0相同网段的IP都会清掉

ip addr flush eth0 192.168.16.19/24  \\ 只清除指定的ip



3、ip route 路由配置

    ip route

(a)、查看路由配置

# ip route show  或 ip route

(b)、配置路由     

  ip route add DESTINATION [via NEXT_HOP] [src SOURCE_ADDRESS] [dev DEVICE]    #

# ip route add 192.168.1.0/24 via 172.16.1.106

如果网卡配置有多个ip时可以指定数据包从哪个网卡出去

# ip route add 192.168.1.0/24 src 172.16.1.106 dev eth1
# ip route show
192.168.1.0/24 dev eth1  scope link  src 172.16.1.106

(c)、删除路由

# ip route del 192.168.0.1/24








本文出自 “菜鸟日志” 博客,请务必保留此出处http://zkxfoo.blog.51cto.com/1605971/1758528

linux网络配置命令 ifconfig 、route 、ip 、ip route

标签:ip   ip link   ip route ifconfig route   

原文地址:http://zkxfoo.blog.51cto.com/1605971/1758528

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!