当前所在位置:珠峰网资料 >> 计算机 >> 计算机等级考试 >> 正文
linux命令:ifconfig和route
发布时间:2010/8/10 10:23:13 来源:城市学习网 编辑:ziteng
  手动设置ip地址命令:#ifconfig eth0 192.168.1.101 netmask 255.255.255.0 broadcast 255.255.255.255
  eth0标示第一块网卡,192.168.1.101 网卡ip地址 netmask 子网掩码 broadcast 广播地址
  上面那条命令以设置好网卡的ip地址了 接下来要配置默认网关(与pc物理连线最近的路由器地址)了
  # route add default gw 192.168.1.100
  add 表示添加路由 default 表示默认 gw 表示网关 192.168.1.100 表示与我pc接的那个路由器ip地址
  测试一下
  #ifconfig eth0 192.168.1.101 netmask 255.255.255.0 broadcast 255.255.255.255
  # route add default gw 192.168.1.100
  root@sniffer-desktop:/home/sniffer# ping baidu.com
  PING baidu.com (220.181.6.184) 56(84) bytes of data.
  64 bytes from 220.181.6.184: icmp_seq=1 ttl=55 time=51.5 ms
  ^C64 bytes from 220.181.6.184: icmp_seq=2 ttl=55 time=51.4 ms
  网络通了
  接下了介绍一下ifconfig 和route命令参数
  root@sniffer-desktop:~# ifconfig eth0 down  down参数 关闭接口 对应的命令up 启动接口
  root@sniffer-desktop:~# ping baidu.com
  ping: unknown host baidu.com
  root@sniffer-desktop:~# ifconfig eth0 up
  root@sniffer-desktop:~# ping baidu.com
  PING baidu.com (220.181.6.184) 56(84) bytes of data.
  ^Z [NextPage]   [1]+  Stopped                 ping baidu.com
  -a 参数 查看所有接口的信息
  root@sniffer-desktop:~# ifconfig -a
  eth0      Link encap:以太网  硬件地址 00:1f:e2:56:34:a2
  inet 地址:192.168.1.101  广播:192.168.1.255  掩码:255.255.255.0
  inet6 地址: fe80::21f:e2ff:fe56:34a2/64 Scope:Link
  UP BROADCAST RUNNING NOARP MULTICAST  MTU:1500  跃点数:1
  接收数据包:102705 错误:0 丢弃:0 过载:0 帧数:0
  发送数据包:66278 错误:0 丢弃:0 过载:0 载波:0
  碰撞:29 发送队列长度:1000
  接收字节:117308368 (117.3 MB)  发送字节:6248995 (6.2 MB)
  中断:19 基本地址:0xdead
  lo        Link encap:本地环回   //环回接口loopback
  inet 地址:127.0.0.1  掩码:255.0.0.0
  inet6 地址: ::1/128 Scope:Host
  UP LOOPBACK RUNNING  MTU:16436  跃点数:1
  接收数据包:306 错误:0 丢弃:0 过载:0 帧数:0
  发送数据包:306 错误:0 丢弃:0 过载:0 载波:0
  碰撞:0 发送队列长度:0
  接收字节:22980 (22.9 KB)  发送字节:22980 (22.9 KB)
  -arp 参数 在接口上启动arp协议
  root@sniffer-desktop:~# ifconfig eth0 -arp
  其他参数可以查看man手册
 [NextPage]   route 命令可以查看man手册的帮助信息有很好的例子:
  EXAMPLES
  route add -net 127.0.0.0 netmask 255.0.0.0 dev lo //添加一条从接口lo(环回口)通往127.0.0.0 这个网段
  adds the normal loopback  entry,  using  netmask  255.0.0.0  and
  associated with the "lo" device (assuming this device was previ‐
  ously set up correctly with ifconfig(8)).
  route add -net 192.56.76.0 netmask 255.255.255.0 dev eth0//添加一条从eth0接口通往192.56.76.0这个网段
  adds a route to the local network 192.56.76.x via  "eth0".   The
  word "dev" can be omitted here.
  route del default  //删除默认路由
  deletes the current default route, which is labeled "default" or
  0.0.0.0 in the destination field of the current routing table.
  route add default gw mango-gw //添加默认路由
  adds a default route (which will  be  used  if  no  other  route
  matches).   All  packets  using  this  route  will  be gatewayed
  through "mango-gw". The device which will actually be  used  for
  that  route  depends on how we can reach "mango-gw" - the static
  route to "mango-gw" will have to be set up before.
  有了这条命令(route)事实上pc可以当个简单的路由器来使用,只是它没有跑路由协议而已。
  dos有对应的命令
  linux                 dos
  ifconfig<------>ipconfig
  route <------->route
  linux下命令的参数更加丰富些
广告合作:400-664-0084 全国热线:400-664-0084
Copyright 2010 - 2017 www.my8848.com 珠峰网 粤ICP备15066211号
珠峰网 版权所有 All Rights Reserved