Linux 网络相关
- [root@localhost ~]# ifconfig
- ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
- inet 192.168.91.128 netmask 255.255.255.0 broadcast 192.168.91.255
- inet6 fe80::613e:a8bf:a776:7dbb prefixlen 64 scopeid 0x20<link>
- ether 00:0c:29:58:49:a9 txqueuelen 1000 (Ethernet)
- RX packets 105173 bytes 31378778 (29.9 MiB)
- RX errors 0 dropped 0 overruns 0 frame 0
- TX packets 279549 bytes 72836445 (69.4 MiB)
- TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
- lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
- inet 127.0.0.1 netmask 255.0.0.0
- inet6 ::1 prefixlen 128 scopeid 0x10<host>
- loop txqueuelen 1 (Local Loopback)
- RX packets 0 bytes 0 (0.0 B)
- RX errors 0 dropped 0 overruns 0 frame 0
- TX packets 0 bytes 0 (0.0 B)
- TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
- [root@localhost ~]# ip addr
- 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN qlen 1
- link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
- inet 127.0.0.1/8 scope host lo
- valid_lft forever preferred_lft forever
- inet6 ::1/128 scope host
- valid_lft forever preferred_lft forever
- 2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
- link/ether 00:0c:29:58:49:a9 brd ff:ff:ff:ff:ff:ff
- inet 192.168.91.128/24 brd 192.168.91.255 scope global ens33
- valid_lft forever preferred_lft forever
- inet6 fe80::613e:a8bf:a776:7dbb/64 scope link
- valid_lft forever preferred_lft forever
- [root@localhost ~]# ifdown ens33
- Connection closed by foreign host.
- Disconnected from remote host(hyclinux-01) at 22:31:38.
- Type `help' to learn how to use Xshell prompt.
执行后连接断开
[root@localhost ~]# ifup ens33
*ifdown 再 ifup 可以在修改指定网卡配置后重启指定的网卡
[root@localhost ~]# ifdown ens33 && ifup ens33
成功断开设备'ens33'
连接已成功激活 (D-Bus 活动路径:/org/freedesktop/NetworkManager/ActiveConnection/3)
设置虚拟网卡
[root@localhost ~]#
在网卡配置文件目录下拷贝 ifcfg-ens33 文件, 更名为 ifcfg-ens33:0, 做如下修改:
- TYPE=Ethernet
- PROXY_METHOD=none
- BROWSER_ONLY=no
- BOOTPROTO=static
- DEFROUTE=yes
- IPV4_FAILURE_FATAL=no
- IPV6INIT=yes
- IPV6_AUTOCONF=yes
- IPV6_DEFROUTE=yes
- IPV6_FAILURE_FATAL=no
- IPV6_ADDR_GEN_MODE=stable-privacy
- NAME=ens33:0
- UUID=32826281-32dd-4e88-af97-8176b8eb1eee
- DEVICE=ens33:0
- ONBOOT=yes
- IPADDR=192.168.91.131
- NETMASK=255.255.255.0
- GATEWAY=192.168.91.2
- [root@localhost ~]# ifconfig
- ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
- inet 192.168.91.128 netmask 255.255.255.0 broadcast 192.168.91.255
- inet6 fe80::613e:a8bf:a776:7dbb prefixlen 64 scopeid 0x20<link>
- ether 00:0c:29:58:49:a9 txqueuelen 1000 (Ethernet)
- RX packets 107714 bytes 31619328 (30.1 MiB)
- RX errors 0 dropped 0 overruns 0 frame 0
- TX packets 281528 bytes 73182413 (69.7 MiB)
- TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
- ens33:0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
- inet 192.168.91.131 netmask 255.255.255.0 broadcast 192.168.91.255
- ether 00:0c:29:58:49:a9 txqueuelen 1000 (Ethernet)
- lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
- inet 127.0.0.1 netmask 255.0.0.0
- inet6 ::1 prefixlen 128 scopeid 0x10<host>
- loop txqueuelen 1 (Local Loopback)
- RX packets 0 bytes 0 (0.0 B)
- RX errors 0 dropped 0 overruns 0 frame 0
- TX packets 0 bytes 0 (0.0 B)
- TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
- [root@localhost ~]# mii-tool ens33 两个命令均可查看网卡是否连接 (网线)
- ens33: negotiated 1000baseT-FD flow-control, link ok
- [root@localhost ~]# ethtool ens33
- Settings for ens33:
- Supported ports: [ TP ]
- Supported link modes: 10baseT/Half 10baseT/Full
- 100baseT/Half 100baseT/Full
- 1000baseT/Full
- Supported pause frame use: No
- Supports auto-negotiation: Yes
- Advertised link modes: 10baseT/Half 10baseT/Full
- 100baseT/Half 100baseT/Full
- 1000baseT/Full
- Advertised pause frame use: No
- Advertised auto-negotiation: Yes
- Speed: 1000Mb/s
- Duplex: Full
- Port: Twisted Pair
- PHYAD: 0
- Transceiver: internal
- Auto-negotiation: on
- MDI-X: off (auto)
- Supports Wake-on: d
- Wake-on: d
- Current message level: 0x00000007 (7)
- drv probe link
- Link detected: yes
问题:
- [root@localhost ~]# cat /etc/resolv.conf
- ; generated by /usr/sbin/dhclient-script
- search localdomain
- nameserver 192.168.91.2
如果在这个文件里修改 dns, 重启机器后该文件的配置会被网卡配置文件中的 dns 覆盖
- [root@localhost ~]# cat /etc/hosts 访问自定义域名时使用 (自定义域名对应的 ip)
- 127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
- ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
- [root@localhost ~]# vim /etc/hosts
- [root@localhost ~]# ping www.baidu.com
- PING www.baidu.com (127.0.0.1) 56(84) bytes of data.
- 64 bytes from localhost (127.0.0.1): icmp_seq=1 ttl=64 time=0.070 ms
- 64 bytes from localhost (127.0.0.1): icmp_seq=2 ttl=64 time=0.085 ms
- 64 bytes from localhost (127.0.0.1): icmp_seq=3 ttl=64 time=0.085 ms
- 64 bytes from localhost (127.0.0.1): icmp_seq=4 ttl=64 time=0.069 ms
- 64 bytes from localhost (127.0.0.1): icmp_seq=5 ttl=64 time=0.074 ms
- 64 bytes from localhost (127.0.0.1): icmp_seq=6 ttl=64 time=0.067 ms
- ^Z
[1]+ 已停止 ping www.baidu.com
- [root@localhost ~]# cat /etc/hosts
- 127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
- ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
- 127.0.0.1 www.baidu.com
* 可以支持一个 ip 对应多个域名
Hosts 文件中一个域名配多个 ip 时以最后配置的对应关系为主
来源: http://www.bubuko.com/infodetail-2534838.html