`

网络命令

阅读更多

转载:http://www.cublog.cn/u3/99388/showart_2006137.html

【查看网卡信息】
[root@rhel52 ~]# ifconfig eth0
eth0      Link encap:Ethernet  HWaddr 00:0C:29:3B:F9:5B 
          inet addr:192.168.98.220  Bcast:192.168.98.255  Mask:255.255.255.0
          inet6 addr: fe80::20c:29ff:fe3b:f95b/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:710 errors:0 dropped:0 overruns:0 frame:0
          TX packets:608 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:62689 (61.2 KiB)  TX bytes:81995 (80.0 KiB)
          Interrupt:67 Base address:0x2024

【配置网卡IP 地址及辅助IP 地址】
格式:ifconfig 网卡名 ip 地址 netmask 子网掩码
[root@rhel52 ~]# ifconfig eth0 192.168.98.220 netmask 255.255.255.0
【配置虚拟网卡 IP 地址】
命令格式: 
ifconfig 网卡名:虚拟网卡 ID IP地址 netmask 子网掩码
[root@rhel52 ~]# ifconfig eth0:1 192.168.98.110
[root@rhel52 ~]# ifconfig
eth0      Link encap:Ethernet  HWaddr 00:0C:29:3B:F9:5B 
          inet addr:192.168.98.220  Bcast:192.168.98.255  Mask:255.255.255.0
          inet6 addr: fe80::20c:29ff:fe3b:f95b/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:1161 errors:0 dropped:0 overruns:0 frame:0
          TX packets:1052 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:100467 (98.1 KiB)  TX bytes:137411 (134.1 KiB)
          Interrupt:67 Base address:0x2024
eth0:1    Link encap:Ethernet  HWaddr 00:0C:29:3B:F9:5B 
          inet addr:192.168.98.110  Bcast:192.168.98.255  Mask:255.255.255.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          Interrupt:67 Base address:0x2024
lo        Link encap:Local Loopback 
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:3375 errors:0 dropped:0 overruns:0 frame:0
          TX packets:3375 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:4189636 (3.9 MiB)  TX bytes:4189636 (3.9 MiB)
[root@rhel52 ~]# ping 192.168.98.110
PING 192.168.98.110 (192.168.98.110) 56(84) bytes of data.
64 bytes from 192.168.98.110: icmp_seq=1 ttl=64 time=1.47 ms
64 bytes from 192.168.98.110: icmp_seq=2 ttl=64 time=0.159 ms
--- 192.168.98.110 ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1001ms
rtt min/avg/max/mdev = 0.159/0.819/1.479/0.660 ms
[root@rhel52 ~]# ifconfig eth0:1 down
[root@rhel52 ~]# ifconfig           
eth0      Link encap:Ethernet  HWaddr 00:0C:29:3B:F9:5B 
          inet addr:192.168.98.220  Bcast:192.168.98.255  Mask:255.255.255.0
          inet6 addr: fe80::20c:29ff:fe3b:f95b/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:1262 errors:0 dropped:0 overruns:0 frame:0
          TX packets:1144 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:108775 (106.2 KiB)  TX bytes:148053 (144.5 KiB)
          Interrupt:67 Base address:0x2024
lo        Link encap:Local Loopback 
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:3379 errors:0 dropped:0 overruns:0 frame:0
          TX packets:3379 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:4189972 (3.9 MiB)  TX bytes:4189972 (3.9 MiB)

【禁用和启用网卡】
命令格式: 
ifconfig 网卡名称 down        #禁用网卡 
ifconfig 网卡名称 up            #启用网卡
命令格式: 
ifdown 网卡名称         #禁用网卡 
ifup 网卡名称              #启用网卡
[root@rhel52 ~]# ifdown lo
[root@rhel52 ~]# ifconfig
eth0      Link encap:Ethernet  HWaddr 00:0C:29:3B:F9:5B 
          inet addr:192.168.98.220  Bcast:192.168.98.255  Mask:255.255.255.0
          inet6 addr: fe80::20c:29ff:fe3b:f95b/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:1456 errors:0 dropped:0 overruns:0 frame:0
          TX packets:1324 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:125107 (122.1 KiB)  TX bytes:169893 (165.9 KiB)
          Interrupt:67 Base address:0x2024
[root@rhel52 ~]# ifup lo
[root@rhel52 ~]# ifconfig
eth0      Link encap:Ethernet  HWaddr 00:0C:29:3B:F9:5B 
          inet addr:192.168.98.220  Bcast:192.168.98.255  Mask:255.255.255.0
          inet6 addr: fe80::20c:29ff:fe3b:f95b/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:1497 errors:0 dropped:0 overruns:0 frame:0
          TX packets:1361 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:128671 (125.6 KiB)  TX bytes:174247 (170.1 KiB)
          Interrupt:67 Base address:0x2024
lo        Link encap:Local Loopback 
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:3379 errors:0 dropped:0 overruns:0 frame:0
          TX packets:3379 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:4189972 (3.9 MiB)  TX bytes:4189972 (3.9 MiB)
[root@rhel52 ~]#
【更改网卡MAC 地址】
命令格式: 
ifconfig 网卡名 hw ether MAC 地址
[root@rhel52 ~]# ifconfig eth0:1 hw ether 00:00:00:00:00:33
SIOCSIFHWADDR: Device or resource busy
[root@rhel52 ~]#
注意:ifconfig 命令修改IP 地址和MAC 地址都是临时生效的哈,重新启动系统后,设置失效。
我们可以通过修改网卡配置文件使其永久生效哈。具体可以看下
 

【网卡配置文件】
[root@rhel52 ~]# vim /etc/sysconfig/network-scripts/ifcfg-eth0
# Intel Corporation 80003ES2LAN Gigabit Ethernet Controller (Serdes)
DEVICE=eth1
BOOTPROTO=none
HWADDR=00:16:97:9E:27:5D
ONBOOT=yes
TYPE=Ethernet
USERCTL=no
IPV6INIT=no
PEERDNS=yes
NETMASK=255.255.255.0
IPADDR=192.168.98.220
【router命令设定网络】
route 命令格式: 
route add default gw ip 地址        #添加默认网关 
route del default gw ip 地址         #删除默认网关
[root@rhel52 network-scripts]# route add default gw 192.168.98.229
[root@rhel52 network-scripts]# route
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
192.168.98.0    *               255.255.255.0   U     0      0        0 eth0
169.254.0.0     *               255.255.0.0     U     0      0        0 eth0
default         192.168.98.229  0.0.0.0         UG    0      0        0 eth0
[root@rhel52 network-scripts]# route del default gw 192.168.98.229
Flags 用来描述该条路由条目的相关信息,如是否活跃,是否为网关等哈,U 表示该条路由条目
为活跃滴,G表示该条路由条目要涉及到网关哈。
【SETUP命令配置】
[root@rhel52 network-scripts]# setup
【配置DNS】
[root@rhel52 /]# vim /etc/resolv.conf
  1 ; generated by /sbin/dhclient-script
  2 search localdomain
  3 nameserver 192.168.98.228
 
【netstat 命令】 
netstat(network  statistics)主要用于检测主机的网络配置和状况, 可以查看显示网络连接 (进
站和出站)、系统路由表、网络接口状态。netstat 支持 Unix、Linux 及Windows 系统,功能也
是非常滴强大哈。
netstat 命令格式: 
netstat [可选项]
netstat 常用的可选项:
选项  说明
-r 或--route  显示路由表
-a 或--all  显示所有连接信息
-t 或--tcp  显示TCP传输协议的连接状况
-u 或--udp  显示UDP传输协议的连接状况
-c 或--continuous 持续列出网络状态,监控连接情况 
-i 或--interfaces 显示网络界面信息表单
-l 或--listening  显示监控中的服务器的 Socket
-n 或--numeric  使用数字方式显示地址和端口号
-p 或--programs  显示正在使用 Socket 的程序识别码和程序名称
-s 或--statistice 显示网络工作信息统计表
【nslookup 测试域名解析 】
[root@rhel52 /]# nslookup www.g.cn
Server:         192.168.98.228
Address:        192.168.98.228#53
Non-authoritative answer:
Name:   www.g.cn
Address: 203.208.39.160
Name:   www.g.cn
Address: 203.208.39.99
Name:   www.g.cn
Address: 203.208.39.104
[root@rhel52 /]#


coffeesen注:相当实用!
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics