第十一节课 linux 网络相关
安装net-tools (ifconfig)
[root@localhost ~]# yum install -y net-tools
[root@localhost ~]# ifconfig
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.247.101 netmask 255.255.255.0 broadcast 192.168.247.255
inet6 fe80::20c:29ff:fe6e:8925 prefixlen 64 scopeid 0x20<link>
ether 00:0c:29:6e:89:25 txqueuelen 1000 (Ethernet)
RX packets 491 bytes 369760 (361.0 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 250 bytes 30647 (29.9 KiB)
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 1000 (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
ifconifg -a 当网卡down掉时,不显示网卡
[root@localhost ~]# ifconfig -a
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.247.101 netmask 255.255.255.0 broadcast 192.168.247.255
inet6 fe80::20c:29ff:fe6e:8925 prefixlen 64 scopeid 0x20<link>
ether 00:0c:29:6e:89:25 txqueuelen 1000 (Ethernet)
RX packets 646 bytes 380167 (371.2 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 302 bytes 35361 (34.5 KiB)
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 1000 (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
ifdown if up命令没尝试成功,不知道安装哪个软件实现
琢磨了下nmcli 命令停止网卡和UP网卡,如下图
[root@localhost ~]# nmcli c down ens33&&nmcli c up ens33
成功停用连接 "ens33"(D-Bus 活动路径:/org/freedesktop/NetworkManager/ActiveConnection/2)
连接已成功激活(D-Bus 活动路径:/org/freedesktop/NetworkManager/ActiveConnection/3)
&&符号代表先执行前一个命令,如果前一个命令成功执行才执行后一个命令。
;(分号)代表执行前一个命令,不管成功与否都执行后面的命令。
增加虚拟网卡
需要用到虚拟网卡的地方 lvs ,keeplived的时候
先复制ifcfg-ens33 到ifcfg-ens33:0
修改ifcfg-ens33:0,去掉DNS和网关 NAME 和DEVICE都改成ens33:0,DNS和网关都去掉
[root@localhost network-scripts]# vim 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=eui64
NAME=ens33:0
UUID=2f847698-fb41-4b3b-9456-153ebadd6677
DEVICE=ens33:0
ONBOOT=yes
IPADDR=192.168.247.102
NETMASK=255.255.255.0
GATEWAY=192.168.247.2
修改好后重新reload ens33配置文件
[root@localhost ~]# nmcli d reapply ens33
成功重新应用连接到设备 "ens33"。
对网卡重启
[root@localhost network-scripts]# nmcli c down ens33 && nmcli c up ens33
成功停用连接 "ens33"(D-Bus 活动路径:/org/freedesktop/NetworkManager/ActiveConnection/5)
连接已成功激活(D-Bus 活动路径:/org/freedesktop/NetworkManager/ActiveConnection/6)
发现子接口 ip a
[root@localhost ~]# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
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 fq_codel state UP group default qlen 1000
link/ether 00:0c:29:6e:89:25 brd ff:ff:ff:ff:ff:ff
altname enp2s1
inet 192.168.247.101/24 brd 192.168.247.255 scope global noprefixroute ens33
valid_lft forever preferred_lft forever
inet 192.168.247.102/24 brd 192.168.247.255 scope global secondary noprefixroute ens33:0
valid_lft forever preferred_lft forever
inet6 fe80::20c:29ff:fe6e:8925/64 scope link noprefixroute
valid_lft forever preferred_lft forever
ifconfig再次查看
[root@localhost ~]# ifconfig
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.247.101 netmask 255.255.255.0 broadcast 192.168.247.255
inet6 fe80::20c:29ff:fe6e:8925 prefixlen 64 scopeid 0x20<link>
ether 00:0c:29:6e:89:25 txqueuelen 1000 (Ethernet)
RX packets 10178 bytes 9188254 (8.7 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 3602 bytes 449065 (438.5 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
ens33:0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.247.102 netmask 255.255.255.0 broadcast 192.168.247.255
ether 00:0c:29:6e:89:25 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 1000 (Local Loopback)
RX packets 24 bytes 2112 (2.0 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 24 bytes 2112 (2.0 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
查看网卡连接状态mii-tool
[root@localhost ~]# mii-tool ens33
ens33: negotiated 1000baseT-FD flow-control, link ok
查看网卡连接状态ethtool
[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
Supported FEC modes: Not reported
Advertised link modes: 10baseT/Half 10baseT/Full
100baseT/Half 100baseT/Full
1000baseT/Full
Advertised pause frame use: No
Advertised auto-negotiation: Yes
Advertised FEC modes: Not reported
Speed: 1000Mb/s
Duplex: Full
Auto-negotiation: on
Port: Twisted Pair
PHYAD: 0
Transceiver: internal
MDI-X: off (auto)
Supports Wake-on: d
Wake-on: d
Current message level: 0x00000007 (7)
drv probe link
Link detected: yes
修改主机名
systemctl set-hostname 名字
[root@localhost ~]# hostnamectl set-hostname maym
[root@localhost ~]# bash
[root@maym ~]#
主机名配置文件
[root@maym ~]# cat /etc/hostname
maym
DNS配置文件
[root@maym ~]# cat /etc/resolv.conf
# Generated by NetworkManager
nameserver 114.114.114.114
hosts文件
/etc/hosts
[root@maym ~]# vim /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.247.2 gateway
一个ip可以对应多个域名
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.247.2 gateway gateway01
~
[root@maym ~]# ping gateway01
PING gateway (192.168.247.2) 56(84) bytes of data.
64 bytes from gateway (192.168.247.2): icmp_seq=1 ttl=128 time=0.210 ms
64 bytes from gateway (192.168.247.2): icmp_seq=2 ttl=128 time=0.100 ms
64 bytes from gateway (192.168.247.2): icmp_seq=3 ttl=128 time=0.127 ms
64 bytes from gateway (192.168.247.2): icmp_seq=4 ttl=128 time=0.098 ms
标签:00,14,2023,bytes,192.168,linux,root,localhost,ens33
From: https://www.cnblogs.com/maym/p/17118369.html