首页 > 系统相关 >2023年2月14日第十一节课 linux 网络相关

2023年2月14日第十一节课 linux 网络相关

时间:2023-02-14 00:23:16浏览次数:42  
标签:00 14 2023 bytes 192.168 linux root localhost ens33

第十一节课 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)

image-20230213214708784

&&符号代表先执行前一个命令,如果前一个命令成功执行才执行后一个命令。

;(分号)代表执行前一个命令,不管成功与否都执行后面的命令。

增加虚拟网卡

需要用到虚拟网卡的地方 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

相关文章

  • linux010之网络管理
    简介:在实际工作中,项目上会给你一个linux系统,然后再给你一个局域网地址,让你将linux的网络配置到局域网上,方便后续操作。如果在虚拟机上配置网络?在linux的网络配置文......
  • linux命令之tr
    #####################https://www.myfreax.com/linux-tr-command/  tr是Linux和Unix系统中的命令行程序,可转换,删除和压缩标准输入的字符,并将结果写入标准输出。tr......
  • linux生成随机密码
    ##########################yum-yinstallpwgenyum-yinstallexpectyum-yinstallopenssl  pwgen生成32位随机密码:大小写字母和数字组成,且无特殊字符[......
  • Linux管理文件命令-tail查看文件结尾的内容
    前言    前面有学习了查看文件开头的内容,那么自然就会有查看结尾的内容,这个命令不仅可以作为查看结尾的内容,还可实时查看文件更新的状态等信息,让我们一起来看看这个......
  • 2023.2.13环保环保监测中心网络新闻发布系统
         2021级《软件工程》课前测试试卷(180分钟) 河北省环保监测中心网络新闻发布系统(卷面成绩40分,占课程过程考核20分) 1、项目需求:河北省环保监测中心网络新闻......
  • linux008之echo命令显示系统变量和常量
    linux中的系统变量和常量:简介:这里说的变量和常量与windows中的环境变量类似,如在windows中配置的java的环境变量,是这么配置的。java_home:xxxxx/bin,这个时候如果在linu......
  • #yyds干货盘点#如何在 Linux 下删除分区
    有时,您可能希望删除Linux系统上的一些磁盘分区,以恢复或重新获得一些存储空间。只需几个简单的步骤,就可以在命令行上轻松完成这一任务。使用fdisk工具删除一个标准分区fd......
  • linux中软件有哪几种安装方式
    一、绿色安装1.找到相应的安装包,例如apache-tomcat-9.0.zip   上传到linux中的opt目录2.解压安装包  unzip  apache-tomcat-9.0.zip3.进入tomcat目录下的bi......
  • x210-2023-02-13
    1、虚拟机能够识别到SD卡读卡器,但是只要一点击连接就会导致蓝屏,由于是在笔记本上,只有两个USB口,尝试过插到另一个USB口,但不可行,又由于SD卡读卡器识别出来的USB为3.0的,所以继......
  • 「考试总结」2023-02-13 联合省选模拟赛 – Day1
    爆搜$\texttt{(dfs)}$$\texttt{Statement}$给定一个$n$个点$m$条边的简单无向图,你需要对所有匹配$S$,把$c^{|S|}$求和,其中$|S|$是匹配......