Linux中20个高级命令

41. ifconfig命令ifconfig用于配置内核常驻网络接口 。它用于在启动时根据需要设置接口 。
检查活动网络接口[rumenz@local ~]$ ifconfig eth0Link encap:Ethe.NETHWaddr 40:2C:F4:EA:CF:0Einet addr:192.168.1.3Bcast:192.168.1.255Mask:255.255.255.0inet6 addr: fe80::422c:f4ff:feea:cf0e/64 Scope:LinkUP BROADCAST RUNNING MULTICASTMTU:1500Metric:1RX packets:163843 errors:0 dropped:0 overruns:0 frame:0TX packets:124990 errors:0 dropped:0 overruns:0 carrier:0collisions:0 txqueuelen:1000RX bytes:154389832 (147.2 MiB)TX bytes:65085817 (62.0 MiB)Interrupt:20 Memory:f7100000-f7120000 loLink encap:Local Loopbackinet addr:127.0.0.1Mask:255.0.0.0inet6 addr: ::1/128 Scope:HostUP LOOPBACK RUNNINGMTU:16436Metric:1RX packets:78 errors:0 dropped:0 overruns:0 frame:0TX packets:78 errors:0 dropped:0 overruns:0 carrier:0collisions:0 txqueuelen:0RX bytes:4186 (4.0 KiB)TX bytes:4186 (4.0 KiB)检查所有网络接口

使用-a显示所有接口的详细信息
[rumenz@local ~]$ ifconfig -aeth0Link encap:EthernetHWaddr 40:2C:F4:EA:CF:0Einet addr:192.168.1.3Bcast:192.168.1.255Mask:255.255.255.0inet6 addr: fe80::422c:f4ff:feea:cf0e/64 Scope:LinkUP BROADCAST RUNNING MULTICASTMTU:1500Metric:1RX packets:163843 errors:0 dropped:0 overruns:0 frame:0TX packets:124990 errors:0 dropped:0 overruns:0 carrier:0collisions:0 txqueuelen:1000RX bytes:154389832 (147.2 MiB)TX bytes:65085817 (62.0 MiB)Interrupt:20 Memory:f7100000-f7120000 loLink encap:Local Loopbackinet addr:127.0.0.1Mask:255.0.0.0inet6 addr: ::1/128 Scope:HostUP LOOPBACK RUNNINGMTU:16436Metric:1RX packets:78 errors:0 dropped:0 overruns:0 frame:0TX packets:78 errors:0 dropped:0 overruns:0 carrier:0collisions:0 txqueuelen:0RX bytes:4186 (4.0 KiB)TX bytes:4186 (4.0 KiB) virbr0Link encap:EthernetHWaddr 0e:30:a3:3a:bf:03inet addr:192.168.122.1Bcast:192.168.122.255Mask:255.255.255.0UP BROADCAST MULTICASTMTU:1500Metric:1RX packets:0 errors:0 dropped:0 overruns:0 frame:0TX packets:0 errors:0 dropped:0 overruns:0 carrier:0collisions:0 txqueuelen:0RX bytes:0 (0.0 B)TX bytes:0 (0.0 B)禁用网卡[rumenz@local ~]$ ifconfig eth0 down启用网卡[rumenz@local ~]$ ifconfig eth0 up为网卡分配 IP 地址
指定 192.168.1.12 作为网卡 eth0 的 IP 地址 。
[rumenz@local ~]$ ifconfig eth0 192.168.1.12更改网卡eth0的子网掩码[rumenz@local ~]$ ifconfig eth0 netmask 255.255.255.更改网卡 eth0 的广播地址[rumenz@local ~]$ ifconfig eth0 broadcast 192.168.1.255为网卡 eth0 分配 IP 地址、网络掩码和广播[rumenz@local ~]$ ifconfig eth0 192.168.1.12 netmask 255.255.255.0 broadcast 192.168.1.255
Note: 如果使用无线网络,则需要使用命令 iwconfig 。欲了解更多 ifconfig 命令示例和用法,请阅读[15 个有用的 ifconfig 命令] 。
42. netstat命令netstat命令显示各种网络相关信息,如网络连接、路由表
列出所有网络端口[rumenz@local ~]$ netstat -aActive UNIX domain sockets (servers and established)Proto RefCnt FlagsTypeStateI-NodePathunix2[ ACC ]STREAMLISTENING741379/run/user/user1/keyring-I5cn1c/gpgunix2[ ACC ]STREAMLISTENING8965/var/run/acpid.socketunix2[ ACC ]STREAMLISTENING18584/tmp/.X11-unix/X0unix2[ ACC ]STREAMLISTENING741385/run/user/user1/keyring-I5cn1c/sshunix2[ ACC ]STREAMLISTENING741387/run/user/user1/keyring-I5cn1c/pkcs11unix2[ ACC ]STREAMLISTENING20242@/tmp/dbus-ghtTjuPN46unix2[ ACC ]STREAMLISTENING13332/var/run/samba/winbindd_privileged/pipeunix2[ ACC ]STREAMLISTENING13331/tmp/.winbindd/pipeunix2[ ACC ]STREAMLISTENING11030/var/run/MySQLd/mysqld.sockunix2[ ACC ]STREAMLISTENING19308/tmp/ssh-qnZadSgJAbqd/agent.3221unix2[ ACC ]STREAMLISTENING436781/tmp/HotShotsunix2[ ACC ]STREAMLISTENING46110/run/user/ravisaive/pulse/nativeunix2[ ACC ]STREAMLISTENING19310/tmp/gpg-zfE9YT/S.gpg-agent....列出所有 TCP 端口[rumenz@local ~]$ netstat -atActive Internet connections (servers and established)Proto Recv-Q Send-Q Local AddressForeign AddressStatetcp00 localhost:mysql*:*LISTENtcp00 *:5901*:*LISTENtcp00 *:5902*:*LISTENtcp00 *:x11-1*:*LISTENtcp00 *:x11-2*:*LISTENtcp00 *:5938*:*LISTENtcp00 localhost:5940*:*LISTENtcp00 ravisaive-OptiPl:domain *:*LISTENtcp00 ravisaive-OptiPl:domain *:*LISTENtcp00 localhost:ipp*:*LISTENtcp00 ravisaive-OptiPle:48270 ec2-23-21-236-70.c:http ESTABLISHEDtcp00 ravisaive-OptiPle:48272 ec2-23-21-236-70.c:http TIME_WAITtcp00 ravisaive-OptiPle:48421 bom03s01-in-f22.1:https ESTABLISHEDtcp00 ravisaive-OptiPle:48269 ec2-23-21-236-70.c:http ESTABLISHEDtcp00 ravisaive-OptiPle:39084 channel-ecmp-06-f:https ESTABLISHED...显示所有端口的统计信息[rumenz@local ~]$ netstat -sIp:4994239 total packets received0 forwarded0 incoming packets discarded4165741 incoming packets delivered3248924 requests sent out8 outgoing packets droppedIcmp:29460 ICMP messages received566 input ICMP message failed.ICMP input histogram:destination unreachable: 98redirects: 293622918 ICMP messages sent0 ICMP messages failedICMP output histogram:destination unreachable: 2918IcmpMsg:InType3: 98InType5: 29362OutType3: 2918Tcp:94533 active connections openings23 passive connection openings5870 failed connection attempts7194 connection resets received....


推荐阅读