Network Cli

最後更新: 2018-11-07

目錄

 


找出本機有的 NIC

 

 

什麼工具都無時

cat /proc/net/dev

Inter-|   Receive                                                     |  Transmit
 face |  bytes      packets  errs drop fifo frame compressed multicast|bytes       packets errs drop fifo colls carrier compressed
    lo:   19459     253         0    0    0     0          0         0 19459       253        0    0    0     0       0          0
  eth0: 47171187713 77128416    0    0    0     0          0         0 32289514985 79506794   0    0    0     0       0          0

ls /sys/class/net/

eth0  eth1  lo  vmbr0  vmbr1  vnet0  vnet1  vnet2  vnet3  win7

ifconfig

ifconfig -a

ip

ip link show

lshw

lshw -class network

  *-network
       description: Ethernet interface
       product: RTL8111/8168B PCI Express Gigabit Ethernet controller
       vendor: Realtek Semiconductor Co., Ltd.
       physical id: 0
       bus info: pci@0000:01:00.0
       logical name: eth0
       version: 01
       serial: 00:19:66:xx:xx:xx
       size: 100Mbit/s
       capacity: 1Gbit/s
       width: 64 bits
       clock: 33MHz
       capabilities: pm vpd msi pciexpress bus_master cap_list rom ethernet physical tp mii 10bt 10bt-fd 100bt 100bt-fd 1000bt 1000bt-fd autonegotiation
       configuration: autonegotiation=off broadcast=yes driver=r8169 driverversion=2.3LK-NAPI duplex=full firmware=N/A ip=192.168.123.10 latency=0 link=yes multicast=yes port=MII speed=100Mbit/s
       resources: irq:40 ioport:e800(size=256) memory:febff000-febfffff memory:febc0000-febdffff

lspci

lspci | grep Ethernet

01:00.0 Ethernet controller: Realtek Semiconductor Co., Ltd. RTL8111/8168B PCI Express Gigabit Ethernet controller (rev 01)

 


NIC 有無插線

 

ifconfig

# Up 時

ifconfig

eth0      Link encap:Ethernet  HWaddr 52:54:00:C9:9C:61
          inet addr:192.168.88.61  Bcast:192.168.88.255  Mask:255.255.255.0
          inet6 addr: fe80::5054:ff:fec9:9c61/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:1735797 errors:0 dropped:169095 overruns:0 frame:0
          TX packets:123524 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:460427181 (439.0 MiB)  TX bytes:9607614 (9.1 MiB)

ip

# Down 時

ip link show

2: eth0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc pfifo_fast state DOWN qlen 1000
    link/ether 52:54:00:c9:9c:61 brd ff:ff:ff:ff:ff:ff

mii-tool

mii-tool eth0

eth0: link ok

ethtool

ethtool eth0

Settings for eth0:
        Supported ports: [ TP MII ]
        Supported link modes:   10baseT/Half 10baseT/Full
                                100baseT/Half 100baseT/Full
                                1000baseT/Half 1000baseT/Full
        Supported pause frame use: No
        Supports auto-negotiation: Yes
        Advertised link modes:  Not reported
        Advertised pause frame use: No
        Advertised auto-negotiation: No
        Speed: 100Mb/s
        Duplex: Full
        Port: MII
        PHYAD: 0
        Transceiver: internal
        Auto-negotiation: off
        Supports Wake-on: pumbg
        Wake-on: g
        Current message level: 0x00000033 (51)
                               drv probe ifdown ifup
        Link detected: yes

 


Disable IPv6

 

有時當 daemon listen 某 ip 時, 會有以下 Error

dmesg

kernel: lo: Disabled Privacy Extensions

原因是 ipv6 在行

查看有無 ipv6

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:65536  Metric:1
          RX packets:101507 errors:0 dropped:0 overruns:0 frame:0
          TX packets:101507 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:6905870 (6.5 MiB)  TX bytes:6905870 (6.5 MiB)

解決方法

<1>

net.ipv6.conf.all.disable_ipv6=1
net.ipv6.conf.default.disable_ipv6=1
net.ipv6.conf.lo.disable_ipv6=1

<2>

/boot/grub/grub.conf

kernel /vmlinuz-2.6 ... "ipv6.disable=1 quiet splash" ...

<3>

/etc/modprobe.d/blacklist.conf

blacklist ipv6

 


Configure DNS

 

<1>

Use "PEERDNS=no". This option will prevent /etc/resolv.conf from being modified by a DHCP server.

PEERDNS=no

/etc/resolv.conf

nameserver 8.8.8.8
nameserver 8.8.4.4

<2>

"DNS1/DNS2" directives will then automatically be added to /etc/resolv.conf

DNS1=8.8.8.8
DNS2=8.8.4.4

 


Prefer IPv4 connections

 

# gai stands for getaddrinfo

/etc/gai.conf

# precedence  <mask>   <value>

#
#    For sites which prefer IPv4 connections change the last line to
#
#precedence ::ffff:0:0/96  100

 


iptab

 

Package: perl-Net-IP-1.26-4.el7.noarch

Output

+----------------------------------------------+
| addrs   bits   pref   class  mask            |
+----------------------------------------------+
|     1      0    /32          255.255.255.255 |
|     2      1    /31          255.255.255.254 |
|     4      2    /30          255.255.255.252 |
|     8      3    /29          255.255.255.248 |
....