ETHRSSPROTOMASK
『壹』 Linux用什么命令设置IP地址啊
Ip命令需要和参数一起使用才能指明精确的显示内容。使用ip addr可以查看当前的网络;使用ip link可以分析网卡的状态;使用ip route可以查看路由表。
所有这些命令都可以和show命令进行搭配。ip address show可以显示当前的IP地址配置;ip link show可以告诉你链路的统计信息;ip route show会显示当前的路由表。
在这个输出内容里面,ip addr show命令展现了你的Linux网络配置中所有接口的信息。例1中展现了两个网卡。lo网卡是它的回环接口,是给进程用来做基于IP协议的通讯的。比较重要的接口是eth0,是这台服务器上第一个以太网接口。你可以从中看到有三个比较重要的信息:MAC地址(用link/ether表示),IPv4地址以及IPv6地址。可以通过验证这些信息来确认是否与你需要使用的一致。
不是所有的Linux系统都会将标准的以太网卡显示为eth0。新的Linux内核会使用biosdevname功能,它会使辨别一张特定的网卡更加容易。设备的名称是唯一的,类似于eno1677736,不过这个命名在不同的Linux系统间也不是标准统一的。
另一个比较有用的来查看Linux网络配置的命令是ip –s link。这个命令展示了从一个网卡发出去的数据包的统计信息。Linux的ip –s link命令(查看例2)在你遭遇网卡故障并且希望能确保网卡在传输中没有丢包的时候会有帮助。
当检查完网络配置之后,可能还需要检查一下路由。可以使用ip route show(见例3)来查看当前的路由表。你将会看到默认路由,它表明了当机器需要访问其他网络的时候需要经过的网关的IP地址。
早在10年前,在Linux服务器上使用ifconfig命令查看当前网络信息这种方法已经开始弃用。
Linux网络栈已经从全盛时期的ifconfig发生变化了,如果现在还在使用ifconfig,那么你会错过很多信息。随着网络栈的变化,ip命令被引进来管理Linux网络配置的各个方面,而ifconfig命令的开发也再没有继续了。
Linux的ifconfig命令并不准确。举个例子,当管理员希望在网卡上配置额外的IP地址时,如果这个地址是使用ip常规命令配置的,那么你使用ifconfig将看不到这个IP地址。正因为如此,在现在很多Linux发行版本中,ifconfig命令已经不再包含于其中了。
『贰』 openwrt接入点ap功能怎么用
上层 DHCP 服务) –有线–> (openwrt) –无线–> (笔记本,手机)
bridged AP 官方配置 wiki : http://wiki.openwrt.org/doc/recipes/bridgedap
配置网络
配置无线
关闭 dnsmasq
home
针对家里的上层拨号路由器 (192.168.1.1) 配置:
config interface ‘loopback’
option ifname ‘lo’
option proto ‘static’
option ipaddr ‘127.0.0.1’
option netmask ‘255.0.0.0’
config interface ‘lan’
option ifname ‘eth0’
option type ‘bridge’
option proto ‘static’
option ipaddr ‘192.168.1.11’
option netmask ‘255.255.255.0’
## 为了 openwrt 可以连接外网,需要配置以下网关和 DNS
option gateway ‘192.168.1’
option dns ‘192.168.1.1’
奇葩的是 DNS 要由上层路由器 代理解析 ,测试用 google 的 DNS 8.8.8.8 不行
在家里配置比较简单,注意 管理地址 不要冲突就好
office
办公室的环境和家里的有些不同,还做了限制:
办公室的网络是 10.x.x.x 网段
禁用了 手动 设置 IP 访问公网,必须要 DHCP 获取地址
因为是两个网段,需要在 openwrt 配置 ip 别名 (ip alias) 进行管理:
alias 官方配置 wiki : http://wiki.openwrt.org/doc/uci/network#aliases
config interface ‘loopback’
option ifname ‘lo’
option proto ‘static’
option ipaddr ‘127.0.0.1’
option netmask ‘255.0.0.0’
//动态获取办公网地址,不然 openwrt 没法上网
config interface ‘lan’
option ifname ‘eth0’
option type ‘bridge’
option proto ‘dhcp’
//手工配置的内网地址,用作管理用
config ‘alias’
option interface ‘lan’
option proto ‘static’
option ipaddr ‘10.10.15.187’
option netmask ‘255.255.255.0’
// 如果上面两个地址分配失败,这个备用地址用来连接管理 openwrt
//需要将笔记本网卡手工设为 192.168.x.x 网段
config ‘alias’
option interface ‘lan’
option proto ‘static’
option ipaddr ‘192.168.1.12’
option netmask ‘255.255.255.0’
上面的配置,都没有指定 gateway 如果网关 不是 真实存且可达的。配置之后,会导致无法登录 openwrt 需要进入安全模式修改配置了。gateway 其实是不需要的,使用网线将路由器和电脑互联, 只要路由器和电脑设为同一网段,掩码一致,就可以直接访问的
/etc/init.d/network restart
重启网络后,可以通过手工设置的办公网地址连接到 openwrt 说明配置生效了
登录查看正确的获取到了 DHCP 地址也,但是 ifconfig 却无法显示 ip alias :
ifconfig
br-lan Link encap:Ethernet HWaddr B0:48:7A:3B:EF:64
inet addr:10.10.15.38 Bcast:10.10.15.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
… …
eth0 Link encap:Ethernet HWaddr B0:48:7A:3B:EF:64
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
… …
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
UP LOOPBACK RUNNING MTU:16436 Metric:1
… …
wlan0 Link encap:Ethernet HWaddr B0:48:7A:3B:EF:64
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
… …
从路由表中也可以看出配置的 IP alias 生效了:
route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 10.10.15.254 0.0.0.0 UG 0 0 0 br-lan
10.10.15.0 0.0.0.0 255.255.255.0 U 0 0 0 br-lan
192.168.1.0 0.0.0.0 255.255.255.0 U 0 0 0 br-lan
这篇文章 may be a bug: alias interface do not show on ifconfig 提到 ip addr
想到 sencondary ip address 使用 ifconfig 是看不到的,安装 opkg install ip 软件包
ip -a
1: lo: LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state UNKNOWN
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
2: eth0: BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master br-lan state UP qlen 1000
link/ether b0:48:7a:3b:ef:64 brd ff:ff:ff:ff:ff:ff
10: br-lan: BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP
link/ether b0:48:7a:3b:ef:64 brd ff:ff:ff:ff:ff:ff
inet 10.10.15.38/24 brd 10.10.15.255 scope global br-lan
inet 192.168.1.12/24 brd 192.168.1.255 scope global br-lan
inet 10.10.15.187/24 brd 10.10.15.255 scope global secondary br-lan
11: wlan0: BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq master br-lan state UP qlen 32
link/ether b0:48:7a:3b:ef:64 brd ff:ff:ff:ff:ff:ff
果然 openwrt 的 alias 其实是 辅助 ip 地址 (secondary ip address)
而不是 ip 别名 (ip alias) 两者区别可以参考下面这篇文章:
从 ip addr add 和 ifconfig 的区别看 linux 网卡 ip 地址的结构
bridge AP vs 虚化化网桥
从路由器的视角来看 bridged AP 有点类似 linux 中虚拟化的桥接 :
brctl show
bridge name bridge id STP enabled interfaces
br-lan 8000.b0487a3aee72 no eth0
wlan0
linux 宿主机的桥接设备还是需要配置可用的 IP 不然下面的虚拟机网络就没法用了。 对于 wr703n 路由器,只有一个 wan / lan 自适应网口 openwrt 中即使 br-lan 网桥地址设置错误 bridged AP 模式可以正常用,只是无法连接管理地址,登录 openwrt 进行管理而已
看得出来 接入点模式 真的很无视路由器的存在哦 -_-#
『叁』 高手指教一下华为路由器的路由配置命令
路由器静态路由配置命令
4.6.1 ip route
配置或删除静态路由。
[ no ] ip route ip-address
{ mask | mask-length } { interfacce-name
| gateway-address } [ preference preference-value
] [ reject | blackhole ]
【参数说明】
ip-address和mask为目的IP地址和掩码,点分十进制格式,由于要求掩码32位中‘1’必须是连续的,因此点分十进制格式的掩码可以用掩码长度mask-length来代替,掩码长度为掩码中连续‘1’的位数。
interfacce-name指定该路由的发送接口名,gateway-address为该路由的下一跳IP地址(点分十进制格式)。
preference-value为该路由的优先级别,范围0~255。
reject指明为不可达路由。
blackhole指明为黑洞路由。
【缺省情况】
系统缺省可以获取到去往与路由器相连子网的子网路由。在配置静态路由时如果不指定优先级,则缺省为60。如果没有指明reject或blackhole,则缺省为可达路由。
【命令模式】
全局配置模式
【使用指南】
配置静态路由的注意事项:
当目的IP地址和掩码均为0.0.0.0时,配置的缺省路由,即当查找路由表失败后,根据缺省路由进行包的转发。
对优先级的不同配置,可以灵活应用路由管理策略,如配置到达相同目的地的多条路由,如果指定相同优先级,则可实现负载分担;如果指定不同优先级,则可实现路由备份。
在配置静态路由时,既可指定发送接口,也可指定下一跳地址,到底采用哪种方法,需要根据实际情况而定:对于支持网络地址到链路层地址解析的接口或点到点接口,指定发送接口即可;对于NBMA接口,如封装X.25或帧中继的接口、拨号口等,支持点到多点,这时除了配置IP路由外,还需在链路层建立二次路由,即IP地址到链路层地址的映射(如dialer
map ip、x.25 map ip或frame-relay map ip等),这种情? 配置静态路由不能指定发送接口,应配置下一跳IP地址。
【举例】
配置缺省路由的下一跳为129.102.0.2。
Quidway(config)#ip route 0.0.0.0 0.0.0.0 129.102.0.2
【相关命令】
show ip route,show ip route detail,show
ip route static
4.6.2 show ip
route
显示路由表摘要信息。
show ip route
【命令模式】
特权用户模式
【使用指南】
该命令输出以列表方式显示路由表,每一行代表一条路由,内容包括:
目的地址/掩码长度
协议
优先级
度量值
下一跳
输出接口
【举例】
Quidway#show ip route
Routing Tables:
Destination/Mask Proto Pref Metric Nexthop Interface
127.0.0.0/8 Static 0 0 127.0.0.1 127.0.0.1(LO0)
127.0.0.1/32 Direct 0 0 127.0.0.1 127.0.0.1(LO0)
138.102.128.0/17 Direct 0 0 138.102.129.7 138.102.129.7(EN0)
202.38.165.0/24 Direct 0 0 202.38.165.1 202.38.165.1(SL1)
【相关命令】
ip route,show ip route detail,show ip
route static
4.6.3 show
ip route detail
显示路由表详细信息
show ip route detail
【命令模式】
特权用户模式
【使用指南】
该命令输出信息帮助用户进行路由方面的故障诊断。
【举例】
Quidway#show ip route detail
Route state description
NoAdv: do not advertiset Int: AS Interior route
Ext: AS External route Del: route to be deleted
Active: current route Retain: route retains in the routing
table
Rej: rejecting route Black: black hole route
Routing Tables:
Generate Default: no
+ = Active Route, - = Last Active, * = Both
Destinations: 4 Routes: 4
Holddown: 0 Delete: 9 Hidden: 0
**Destination: 127.0.0.0 Mask: 255.0.0.0
Protocol: *Static Preference: 0
NextHop: 127.0.0.1 Interface: 127.0.0.1(LO0)
State: $#@60;NoAdv Int Active Retain Rej$#@62;
Age: 19:31:06 Metric: 0/0
**Destination: 127.0.0.1 Mask: 255.255.255.255
Protocol: *Direct Preference: 0
NextHop: 127.0.0.1 Interface: 127.0.0.1(LO0)
State: $#@60;NoAdv Int Active Retain$#@62;
Age: 114:03:05 Metric: 0/0
Holddown路由指的是:一些distance vector 路由协议(如RIP),为了避免错误路由的扩散,提高路由不可达信息的快速准确传播,而采用的一种路由发布策略。它往往在一段时间间隔内固定地发布某条路由,而不管当前实际找回的到同一目的的路由发生了什么变化。其细节参见具体的路由协议。
在路由表统计中显示的是当前被Holddown的路由数目。有些路由由于某种原因(如接口Down)暂时不可用,但是又不希望被删除,我们把这种路由隐藏起来。以便以后能重新恢复在路由表统计中显示的是当前被隐藏的路由数目。
【相关命令】
ip route,show ip route,show ip route static
4.6.4 show
ip route static
显示静态路由表。
show ip route static
【命令模式】
特权用户模式
【使用指南】
根据该命令输出信息,可以帮助用户确认对静态路由的配置是否正确。
【举例】
Quidway#show ip route static
Static routes for family INET: (* indicates gateway(s)
in use)
1.2.3.0/24 pref 60 $#@60;Int$#@62; intf EN0
127.0.0.0/8 pref 0 $#@60;NoAdv Int Retain Rej$#@62; intf 127.0.0.1
以列表的方式显示静态路由表,每一行代表一条静态路由,从左到右依次为:
目的地址/掩码长度
优先级
$#@60;状态参数$#@62;
输出接口和下一跳
【相关命令】
ip route,show ip route,show ip route detail
路由器IP性能配置命令
4.5.1 clear ip counters
清除IP统计信息。
clear ip counters
【命令模式】
特权用户模式
【使用指南】
在某些特殊情况下,需要清除IP统计信息,重新进行统计。
【举例】
清除IP统计信息。
Quidway#clear ip counters
【相关命令】
show ip interface,show ip traffic
4.5.2 ifquelen ip
配置IP接收队列长度。
ifquelen ip queue-length
【参数说明】
queue-length为接口队列长度。
【命令模式】
全局配置模式
【使用指南】
配置IP接收队列长度,会影响系统运行效率,最好在技术支持人员的指导下进行。
【举例】
配置IP的接收队列为70。
Quidway(config)#ifquelen ip 70
【相关命令】
show ip interface
4.5.3 ifquelen arp
配置ARP接收队列长度。
ifquelen arp queue-length
【参数说明】
queue-length为接口队列长度。
【命令模式】
全局配置模式
【使用指南】
配置ARP接收队列长度,可能会影响到以太网口运行效率,最好在技术支持人员的指导下配置。
【举例】
配置ARP的接收队列长度为70。
Quidway(config)#ifquelen arp 70
【相关命令】
show ip interface
4.5.4 ip tcp header-compression
允许或禁止接口上TC 文头压缩。
[ no ] ip tcp header-compression
【缺省情况】
接口上缺省为禁止TCP报文头压缩。
【命令模式】
接口配置模式
【使用指南】
在低速广域网线路上运行PPP协议时,由于TCP报文头占全部传输数据的很大比例,这时可以对TCP报文头压缩以提高数据传输效率。
【举例】
在PPP接口Serial0上允许TCP报文头压缩。
Quidway(config-if-Serial0)#ip tcp header-compression
【相关命令】
encapsulation ppp
4.5.5 show ip cache
显示IP路由缓冲。
show ip cache
【命令模式】
特权用户模式
【使用指南】
显示IP最近使用过的路由,帮助用户进行故障诊断。
【举例】
Quidway#show ip cache
Route to destination 129.102.100.141:
Destination NetMask Type Interface GateWay
129.102.100.141 255.255.255.255 direct Ethernet0
上面显示信息表示最近刚使用过的路由是到达129.102.100.141的路由。该路由是一条直接路由,输出接口为Ethernet0。
【相关命令】
ip route
4.5.6 show ip interface
显示IP接口信息。
show ip interface [ interface-type interface-number ]
【参数说明】
interface-type为接口类型。
interface-number为接口编号。
【缺省情况】
如果不指定接口,则缺省显示全部IP接口信息。
【命令模式】
特权用户模式
【使用指南】
该命令输出接口上全部与IP有关的信息,有助于故障诊断。
【举例】
Quidway#show ip interface serial 0
Interface is Serial0, Index is 2
ifFlags=8004 $#@60;NBMA,MULTICAST$#@62;
protocol is x25 dte ietf, MTU is 1500, speed is 64000 bps
input queue is 0/75/0 (current/max/drops)
output queue is 0/75/0 (current/max/drops)
0 packets input, 0 bytes, 0 multicasts
0 input packets dropped, 0 no protocols, 0 input errors
0 packets output, 0 bytes, 0 multicasts, 0 output errors
上面显示信息表示接口Serial0 编号为2;处于NBMA模式,支持组播;该接口封装的链路层协议是X.25协议,最大传输单元是1500字节,传输速率为64000bps。再以下的信息主要反映了该接口报文的收发情况,比如说接收和发送队列的最大长度、当前队列中报文数和由于队列满而丢弃报文数,接收和发送的报文数,接收和发送的组播报文数,不能识别的报文数等等。
【相关命令】
show interface
4.5.7 show ip traffic
显示IP流量统计信息。
show ip traffic
【命令模式】
特权用户模式
【使用指南】
该命令显示IP收发和拆包、组包的统计信息,有助于故障诊断。
【举例】
Quidway#show ip traffic
IP statistics:
Rcvd: 1370 total, 1349 local destination
0 format errors, 0 checksum errors
0 unknown protocol, 0 bad options
Frags: 0 fragment rcvd, 0 fragment dropped
0 reassembled, 0 timeouts
0 fragmented, 0 couldnt fragment, 0 fragment sent
Sent: 359 generated, 0 forwarded, 0 raw ip packets
0 dropped, 0 no route, 0 Compress fails
ICMP statistics:
Rcvd: 0 format errors, 0 checksum errors
0 redirects, 0 unreachable, 14 echo, 0 echo reply
0 mask requests, 0 mask replies, 0 quench
0 parameter, 0 timestamp, 0 info request
Sent: 0 redirects, 0 unreachable, 0 echo, 14 echo reply
0 mask requests, 0 mask replies, 0 quench
0 parameter problem, 0 timestamp, 0 info reply
以上显示信息包括:
IP 统计信息:
接收:接收到1664 个报文,其中1638 个报文送给上层协议,没有报文格式错,没有报文校验错,没有未知协议报文,没有报文选项错。
分片:没有收到分片,没有丢弃分片,重装成功的分片数为0,超时分片为数为0;分组成功的报文数为0,不能被分组的报文数为0,被创建发送分片数为0。
发送:产生报文470 个,被转发报文数为0,产生原始IP报文数为0,被丢弃报文数为0,无法路由的报文的报文数为0,压缩失败的报文数为0。
ICMP统计信息:
接收:接收到格式错报文数为0,校验字错报文数为0,重定向报文数为0,不可达报文数为0,echo请求报文16个, echo应答报文数为0,掩码请求报文数为0,掩码应答报文数为0,源站抑制报文数为0,参数错报文数为0,时间戳请求报文数为0,信息请求报文数为0。
发送:发送重定向报文数为0,目的站不可达报文数为0,echo请求报文数为0,echo应答报文16 个,掩码请求报文数为0,掩码应答报文数为0,源站抑制报文数为0,参数错报文数为0,时间戳请求报文数为0,信息应答报文数为0。
【相关命令】
show interface,show ip interface,clear ip counters
4.5.8 show tcp brief
显示TCP连接状态。
show tcp brief
【命令模式】
特权用户模式
【使用指南】
该命令显示全部TCP连接状态,使用户随时监控TCP连接。
【举例】
Quidway#show tcp brief
LocalAddress LocalPort ForeignAddress ForeignPort State
129.102.100.142 23 129.102.001.092 1038 ESTABLISHED
000.000.000.000 23 000.000.000.000 0 LISTEN
以上显示信息表示:一个TCP连接已经建立,该TCP连接的本地IP地址为129.102.100.142,本地端口号为23,远地IP地址为129.102.1.92,远地端口号为1038,另外本地有一个对23号端口监听的服务器。
【相关命令】
show client
4.5.9 tcp finwait-time
配置TCP finwait定时器。
tcp finwait-time time-value
【参数说明】
time-value为TCP finwait定时器值,单位秒,范围76~3600。
【缺省情况】
TCP finwait定时器缺省为675秒。
【命令模式】
全局配置模式
【使用指南】
当TCP的连接状态由FIN_WATI_1变为FIN_WAIT_2时启动finwait定时器。若finwait定时器超时前仍未收到FIN报文,则TCP连接被终止。
对该参数的配置最好在技术支持人员的指导下进行。
【举例】
配置TCP finwait定时器的值为675秒。
Quidway(config)#tcp finwait-time 675
【相关命令】
tcp synwait-time,tcp window-size
4.5.10 tcp synwait-time
配置TCP synwait定时器。
tcp synwait-time time-value
【参数说明】
time-value为TCP synwait 定时器值,单位秒,范围2~600。
【缺省情况】
TCP synwait定时器缺省值为75秒。
【命令模式】
全局配置模式
【使用指南】
当发送syn报文时,TCP启动synwait定时器,若synwait超时前未收到回应报文,则TCP连接将被终止。
对该参数的配置最好在技术支持人员的指导下进行。
【举例】
配置TCP synwait定时器为75秒。
Quidway(config)#tcp synwait-time 75
【相关命令】
tcp finwait-time,tcp window-size
4.5.11 tcp window-size
配置面向连接Socket的收发缓冲区大小。
tcp window-size window-size
【参数说明】
window-size为面向连接Socket的收发缓冲区大小,单位K字节,范围1~32。
【缺省情况】
面向连接Socket的收发缓冲区大小缺省为4K字节。
【命令模式】
全局配置模式
【使用指南】
对该参数的配置最好在技术支持人员的指导下进行。
【举例】
配置面向连接Socket的收发缓冲区大小为4K字节。
Quidway(config)#tcp window-size 4
【相关命令】
tcp finwait-time,tcp synwait-time
【end】
『肆』 linux下怎么判断网卡异常网卡状态
ip link 命令 或者 通过mii-tool指令
[root@localhost
root]# mii-tool
eth0:
negotiated 100baseTx-FD, link ok
eth1:
no link
或
[root@localhost
root]# mii-tool -v
eth0:
negotiated 100baseTx-FD, link ok
proct
info: vendor 00:50:43, model 2 rev 3
basic
mode: autonegotiation
enabled
basic
status: autonegotiation complete, link ok
capabilities:
100baseTx-FD 100baseTx-HD 10baseT-FD 10baseT-HD
advertising:
100baseTx-FD 100baseTx-HD 10baseT-FD 10baseT-HD flow-control
link
partner: 100baseTx-FD 100baseTx-HD 10baseT-FD 10baseT-HD
eth1:
no link
proct
info: vendor 00:50:43, model 2 rev 3
basic
mode: autonegotiation
enabled
basic
status: no link
capabilities:
100baseTx-FD 100baseTx-HD 10baseT-FD 10baseT-HD
advertising:
100baseTx-FD 100baseTx-HD 10baseT-FD 10baseT-HD flow-control
或
[root@localhost
root]# mii-tool -w
21:20:33
eth0: negotiated 100baseTx-FD, link ok
21:20:33
eth1: no link
//mii-tool主要是用于配置网卡工作模式的指令,同时也可以进行查询、监控等工作!
2)
[root@localhost /]# /etc/init.d/network status
Configured devices:
lo eth0 eth1
Currently active devices:
lo eth0
等同于
[root@localhost root]# service --status-all
............
............
Configured devices:
lo eth0 eth1
Currently active devices:
lo eth0
............
............
3)ifconfig -a
[root@localhost /]# ifconfig -a
eth0 Link encap:Ethernet HWaddr 00:09:6B:09:08:FC
inet addr:192.168.10.1 Bcast:192.168.10.255 Mask:255.255.255.0
inet6 addr: fe80::209:6bff:fe09:8fc/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:106732953 errors:0 dropped:0 overruns:0 frame:0
TX packets:104379788 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:100
RX bytes:2351331877 (2.1 GiB) TX bytes:391707945 (373.5 MiB)
Base address:0x2500 Memory:fbfe0000-fc000000
eth1 Link encap:Ethernet HWaddr 00:09:6B:09:08:FD
BROADCAST MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:0 (0.0 b) TX bytes:0 (0.0 b)
Base address:0x2540 Memory:fbfc0000-fbfe0000
4)ethtool
ethtool eth0
Settings for eth0:
Supported ports: [ MII ]
Supported link modes: 10baseT/Half 10baseT/Full
100baseT/Half 100baseT/Full
1000baseT/Half 1000baseT/Full
Supports auto-negotiation: Yes
Advertised link modes: 10baseT/Half 10baseT/Full
100baseT/Half 100baseT/Full
1000baseT/Half 1000baseT/Full
Advertised auto-negotiation: Yes
Speed: 100Mb/s
Duplex: Full
Port: Twisted Pair
PHYAD: 1
Transceiver: internal
Auto-negotiation: on
Supports Wake-on: g
Wake-on: d
Current message level: 0x000000ff (255)
Link detected: yes
ethtool eth1
Settings for eth1:
Supported ports: [ MII ]
Supported link modes: 10baseT/Half 10baseT/Full
100baseT/Half 100baseT/Full
1000baseT/Half 1000baseT/Full
Supports auto-negotiation: Yes
Advertised link modes: 10baseT/Half 10baseT/Full
100baseT/Half 100baseT/Full
1000baseT/Half 1000baseT/Full
Advertised auto-negotiation: Yes
Speed: Unknown! (0)
Duplex: Half
Port: Twisted Pair
PHYAD: 1
Transceiver: internal
Auto-negotiation: on
Supports Wake-on: g
Wake-on: d
Current message level: 0x000000ff (255)
Link detected: no
从上面可以看出eth0 处于连接状态,eth1没有连接
二. 查看网卡的配置
一般在linux下查看网络配置可以使用ifconfig命令,可以显示当前网卡的基本配置信息。
终端输入ifconfig 会出现一下内容:
eth0
Link encap:Ethernet HWaddr 00:0C:29:0C:4B:0F
inet addr:192.168.37.128 Bcast:192.168.37.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:33 errors:0 dropped:0 overruns:0 frame:0
TX packets:17 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:100
RX bytes:2823 (2.7 Kb)
TX bytes:2722 (2.6 Kb)
Interrupt:10 Base address:0x1080
他们分别表示:
Eth0:网络接口
link encap:网络类型
HWaddr:网卡物理地址
Inet addr :IP地址
Bcast:广播地址
Mask:子网掩码
UP:正在使用的网络接口
RX packets,TX packets接收和传输的数据包个数
RX byte,TX byte表示接搜和传输的具体数目
Interrupt:终端信息
Base address:内存地址
三. 网卡配置文件
如果希望每次启动linux时,都能为你的网卡配置正确的网络地址,可以采用下列两种方法:
1. 每次开机后,使用ifconfig手动重新设置网卡的配置;
2. 在开机流程中,将网络配置的设置保存在某些RC Script中。
第一种方式麻烦,第二种方式涉及到在哪个RC Script中配置网卡是比较适当的?
Linux启动过程中会执行以下三个RC Script。
1. /etc/rc.d/init.d/rc.sysinit;
2. /etc/rc.d/init.d/rc;
3. /etc/rc.d/init.d/rc.local
为了维护Linux的稳定性,建议不要修改前两项。但是,用ifconfig配置第三个RC Script的话,导致严重的问题:由于最后执行这个程序,在其执行之前,可能已经执行了数十项网络服务。因此,会造成一堆网络服务因为网卡尚未启动而无法顺利的启动。
四、网卡配置文件
解决上述问题的方法:每一个网络介质都对应一个配置文件,超级用户可以通过这些配置文件来配置网卡。
网卡配置文件存放在 /etc/sysconfig/network-scripts/目录中;
/etc/sysconfig/network-scripts/ifcfg-interface-name
设置文件ifcfg-interface-name包含了初始化接口所需的大部分周详信息。其中interface-name将根据网卡的类型和排序而不
同,一般其名字为eth0、eth1、ppp0等,其中eth表示以太(eth0)类型网卡,0表示第一块网卡,1表示第二块网卡,而ppp0则表示第一 个point-to-poirt protocol网络接口。在ifcfg文件中定义的各项目取决于接口类型。
下面的值较问常见:
》DEVICE=name ,其中,name是物理设备名。
》IPADDR=addr,其中,addr是IP地址。
》NETMASK=mask,其中,mask是网络掩码值。
》NETWORK=addr,其中addr是网络地址。
》BROADCAST=addr,其中,addr是广播地址。
》GATEWAY=addr,其中addr是网关地址。
》ONBOOT=answer,其中,answer是yes(引导时激活设备)或no(引导时不激活设备)
》USERCTL=answer,其中,answer是yes(非root用户能控制该设备)或no
》BOOTPROTO=proto,其中,proto取下列值之一:none,引导时不使用协议;static静态分配地址;bootp,使用BOOTP协议,或dhcp,使用DHCP协议。
(2)根据上述各参数的意义,设定linpcl.lintec.e.cn机器的设置文件如下:
[root@linpcl root]#cat /etc/sysconfig/networking/devices/ifcfg-rth0
DEVICE=eth0
ONBOOT=yes
BOOTPROTO=static
IPADDR=192.168.0.2
NETMASK=255.255.255.0
GATEWAY=192.168.0.1
『伍』 入接口选择vlan 10 出接口选择上联口eth1
先看看网络拓扑,MW305R+刷OP,单口上联ROS。设置两个SSID,一个是无VLAN,一个VLAN ID 200
下面是OP的网络配置:
config interface 'lan'
option type 'bridge'
option _orig_ifname 'eth0 radio0.network1'
option _orig_bridge 'true'
option proto 'none'
option delegate '0'
option ifname 'eth0'
config interface 'wan'
option ifname 'eth1'
option proto 'dhcp'
option delegate '0'
config switch
option name 'switch0'
option reset '1'
option enable_vlan '1'
config switch_vlan
option device 'switch0'
option vlan '1'
option ports '0 1 2 3 4'
config switch_vlan
option device 'switch0'
option vlan '2'
option vid '200'
option ports '0t 1t'
config interface 'VLan_200'
option type 'bridge'
option proto 'none'
option ifname 'eth0.200'
option delegate '0'
无线部分配置:
config wifi-device 'radio0'
option type 'mac80211'
option hwmode '11g'
option path 'platform/qca953x_wmac'
option htmode 'HT20'
option channel 'auto'
option txpower '12'
option country 'US'
config wifi-iface
option device 'radio0'
option mode 'ap'
option encryption 'none'
option ssid 'OpenWrt_Lan'
option network 'lan'
option isolate '1'
config wifi-iface
option device 'radio0'
option mode 'ap'
option encryption 'none'
option ssid 'OpenWrt_200'
option network 'VLan_200'
option isolate '1'
这样设置后,无VLan的接口会失效,不能从ROS获取IP。如果两个SSID都设置VLAN ID,ROS也增加对应接口,这样就没有问题。
该如何设置才能使得无VLAN的接口可以正常上联
『陆』 如何关闭linuxredhat设置ip地址
Linux命令行下配置IP地址的几种配置方法:
即时生效(重启后失效):
ifconfig eth0 192.168.1.102 netmask 255.255.255.0 //添加IP地址
route add default gw 192.168.1.1 //添加网关
启动生效:
vim /etc/sysconfig/network-scripts/ifcfg-eth0 //(某些版本中可能没有vim这个编辑器比如centos,大家可能用vi替换)
IPADDR=192.168.1.102 //添加IP地址
NETMASK=255.255.255.0 //掩码
GATEWAY=192.168.1.1 //添加网关
最后结果如下:
DEVICE=eth0
BOOTPROTO=static
IPADDR=192.168.1.102
NETMASK=255.255.255.0
GETEWAY=192.168.1.1
ONBOOT=yes
TYPE=Ethernet
注:BOOTPROTO只有在static(静态)模式下才可以使用设置的IP信息
修改dns
vim /etc/resolv.conf
修改后可即时生效,启动同样有效
形式
加入nameserver= ***.***.***.***
最多可有三个,作为上一个失败后的候选
修改host name
即时生效:
hostname fc2
启动生效:
vim /etc/sysconfig/network
形式如下:
NETWORKING=yes
HOSTNAME=rh-linux.fc.org
##########################################################
首先,先了解传统的网络配置命令:
1. 使用ifconfig命令配置并查看网络接口情况
示例1: 配置eth0的IP,同时激活设备:
ifconfig eth0 192.168.4.1 netmask 255.255.255.0 up
示例2: 配置eth0别名设备 eth0:1 的IP,并添加路由
ifconfig eth0:1 192.168.4.2
route add –host 192.168.4.2 dev eth0:1
示例3:激活(禁用)设备
ifconfig eth0:1 up(down)
示例4:查看所有(指定)网络接口配置
ifconfig (eth0)
—————————
2. 使用route 命令配置路由表
示例1:添加到主机路由
route add –host 192.168.4.2 dev eth0:1
route add –host 192.168.4.1 gw 192.168.4.250
示例2:添加到网络的路由
route add –net IP netmask MASK eth0
route add –net IP netmask MASK gw IP
route add –net IP/24 eth1
示例3:添加默认网关
route add default gw IP
示例4:删除路由
route del –host 192.168.4.1 dev eth0:1
示例5:查看路由信息
route 或 route -n (-n 表示不解析名字,列出速度会比route 快)
—————————
3.ARP 管理命令
示例1:查看ARP缓存
arp
示例2:添加
arp –s IP MAC
示例3: 删除
arp –d IP
—————————
4.ip是iproute2软件包里面的一个强大的网络配置工具,它能够替代一些传统的网络管理工具。
例如:ifconfig、route等,
上面的示例完全可以用下面的ip命令实现,而且ip命令可以实现更多的功能.下面介绍一些示例:
4.0 ip命令的语法
ip [OPTIONS] OBJECT [COMMAND [ARGUMENTS]]
4.1 ip link set–改变设备的属性.缩写:set、s
示例1:up/down 起动/关闭设备。
ip link set dev eth0 up
这个等于传统的
ifconfig eth0 up
ifconfig eth0 down
示例2:改变设备传输队列的长度。
参数:txqueuelen NUMBER或者txqlen NUMBER
ip link set dev eth0 txqueuelen 100
示例3:改变网络设备MTU(最大传输单元)的值。
ip link set dev eth0 mtu 1500
示例4: 修改网络设备的MAC地址。
参数: address LLADDRESS
ip link set dev eth0 address 00:01:4f:00:15:f1
4.2 ip link show–显示设备属性.缩写:show、list、lst、sh、ls、l
-s选项出现两次或者更多次,ip会输出更为详细的错误信息统计。
示例:
ip -s -s link ls eth0
这个命令等于传统的
ifconfig eth0
—————————
5.1 ip address add–添加一个新的协议地址. 缩写:add、a
示例1:为每个地址设置一个字符串作为标签。为了和Linux-2.0的网络别名兼容,这个字符串必须以设备名开头,接着一个冒号,
ip addr add local 192.168.4.1/28 brd + label eth0:1 dev eth0
等价于
ifconfig eth0:5 192.168.4.1/28
ip addr add local 192.168.4.1/28 dev eth0
示例2: 在以太网接口eth0上增加一个地址192.168.20.0,掩码长度为24位(155.155.155.0),标准广播地址,标签为 eth0:Alias:
ip addr add 192.168.4.2/24 brd + dev eth1 label eth1:1
这个命令等于传统的:
ifconfig eth1:1 192.168.4.2/24
5.2 ip address delete–删除一个协议地址. 缩写:delete、del、d
ip addr del 192.168.4.1/24 brd + dev eth0 label eth0:Alias1
5.3 ip address show–显示协议地址. 缩写:show、list、lst、sh、ls、l
ip addr ls eth0
5.4.ip address flush–清除协议地址. 缩写:flush、f
示例1 : 删除属于私网10.0.0.0/8的所有地址:
ip -s -s a f to 10/8
示例2 : 取消所有以太网卡的IP地址
ip -4 addr flush label “eth0″
—————————
6. ip neighbour–neighbour/arp表管理命令
缩写 neighbour、neighbor、neigh、n
命令 add、change、replace、delete、fulsh、show(或者list)
6.1 ip neighbour add — 添加一个新的邻接条目
ip neighbour change–修改一个现有的条目
ip neighbour replace–替换一个已有的条目
缩写:add、a;change、chg;replace、repl
示例1: 在设备eth0上,为地址10.0.0.3添加一个permanent ARP条目:
ip neigh add 10.0.0.3 lladdr 0:0:0:0:0:1 dev eth0 nud perm
示例2:把状态改为reachable
ip neigh chg 10.0.0.3 dev eth0 nud reachable
6.2.ip neighbour delete–删除一个邻接条目
示例1:删除设备eth0上的一个ARP条目10.0.0.3
ip neigh del 10.0.0.3 dev eth0
6.3.ip neighbour show–显示网络邻居的信息.缩写:show、list、sh、ls
示例1: ip -s n ls 193.233.7.254
193.233.7.254. dev eth0 lladdr 00:00:0c:76:3f:85 ref 5 used 12/13/20 nud reachable
6.4.ip neighbour flush–清除邻接条目. 缩写:flush、f
示例1: (-s 可以显示详细信息)
ip -s -s n f 193.233.7.254
—————————
7. 路由表管理
7.1.缩写 route、ro、r
7.5.路由表
从Linux-2.2开始,内核把路由归纳到许多路由表中,这些表都进行了编号,编号数字的范围是1到255。另外,
为了方便,还可以在/etc/iproute2/rt_tables中为路由表命名。
默认情况下,所有的路由都会被插入到表main(编号254)中。在进行路由查询时,内核只使用路由表main。
7.6ip route add — 添加新路由
ip route change — 修改路由
ip route replace — 替换已有的路由
缩写:add、a;change、chg;replace、repl
示例1: 设置到网络10.0.0/24的路由经过网关193.233.7.65
ip route add 10.0.0/24 via 193.233.7.65
示例2: 修改到网络10.0.0/24的直接路由,使其经过设备mmy
ip route chg 10.0.0/24 dev mmy
示例3: 实现链路负载平衡.加入缺省多路径路由,让ppp0和ppp1分担负载(注意:scope值并非必需,它只不过是告诉内核,这个路由要经过网关而不是直连 的。实际上,如果你知道远程端点的地址,使用via参数来设置就更好了)。
ip route add default scope global nexthop dev ppp0 nexthop dev ppp1
ip route replace default scope global nexthop dev ppp0 nexthop dev ppp1
示例4: 设置NAT路由。在转发来自192.203.80.144的数据包之前,先进行网络地址转换,把这个地址转换为193.233.7.83
ip route add nat 192.203.80.142 via 193.233.7.83
示例5: 实现数据包级负载平衡,允许把数据包随机从多个路由发出。weight 可以设置权重.
ip route replace default equalize nexthop via 211.139.218.145 dev eth0 weight 1 nexthop via 211.139.218.145 dev eth1 weight 1
7.7.ip route delete– 删除路由
缩写:delete、del、d
示例1:删除上一节命令加入的多路径路由
ip route del default scope global nexthop dev ppp0 nexthop dev ppp1
7.8.ip route show — 列出路由
缩写:show、list、sh、ls、l
示例1: 计算使用gated/bgp协议的路由个数
ip route ls proto gated/bgp |wc
1413989179010
示例2: 计算路由缓存里面的条数,由于被缓存路由的属性可能大于一行,以此需要使用-o选项
ip -o route ls cloned |wc
159254318707
示例3: 列出路由表TABLEID里面的路由。缺省设置是table main。TABLEID或者是一个真正的路由表ID或者是/etc/iproute2/rt_tables文件定义的字符串,
或者是以下的特殊值:
all — 列出所有表的路由;
cache — 列出路由缓存的内容。
ip ro ls 193.233.7.82 tab cache
示例4: 列出某个路由表的内容
ip route ls table fddi153
示例5: 列出默认路由表的内容
ip route ls
这个命令等于传统的: route
7.9.ip route flush — 擦除路由表
示例1: 删除路由表main中的所有网关路由(示例:在路由监控程序挂掉之后):
ip -4 ro flush scope global type unicast
示例2:清除所有被克隆出来的IPv6路由:
ip -6 -s -s ro flush cache
示例3:在gated程序挂掉之后,清除所有的BGP路由:
ip -s ro f proto gated/bgp
示例4: 清除所有ipv4路由cache
ip route flush cache
*** IPv4 routing cache is flushed.
7.10ip route get — 获得单个路由 .缩写:get
『柒』 跪求大神指点linux中的路由机制
不明白host2网笑饥关设置成172.16.1.100是坦和什么意思,不通,多半是因碰信返为172.16.1.100没有到172.16.4.0/24的路由