Linux网络设置

查看网络接口信息

  • 查看所有活动的网络接口信息
    ifconfig
  • 查看指定网络接口号
    ifconfig 网络接口

ifconfig命令的使用
ifconfig -a 显示网卡信息

[root@localhost ~]# ifconfig -a
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.71.131  netmask 255.255.255.0  broadcast 192.168.71.255
        inet6 fe80::c48d:a362:6194:6ca4  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:23:15:64  txqueuelen 1000  (Ethernet)
        RX packets 511  bytes 51048 (49.8 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 242  bytes 27533 (26.8 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 280  bytes 27320 (26.6 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 280  bytes 27320 (26.6 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

virbr0: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500
        inet 192.168.122.1  netmask 255.255.255.0  broadcast 192.168.122.255

ifconfig ens33 看主配置网卡接口信息

[root@localhost ~]# ifconfig ens33
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.71.129  netmask 255.255.255.0  broadcast 192.168.71.255
        inet6 fe80::a489:4a20:7837:4788  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:23:15:64  txqueuelen 1000  (Ethernet)

systemctl status NetworkManager 管理和监控网络设置的守护进程

[root@localhost ~]# systemctl status NetworkManager
● NetworkManager.service - Network Manager
   Loaded: loaded (/usr/lib/systemd/system/NetworkManager.service; enabled; vendor preset: enabled)
   Active: active (running) since 五 2021-04-23 22:37:39 CST; 3 weeks 4 days ago
     Docs: man:NetworkManager(8)
 Main PID: 6244 (NetworkManager)
    Tasks: 4
   CGroup: /system.slice/NetworkManager.service
           ├─ 6244 /usr/sbin/NetworkManager --no-daemon
           └─19369 /sbin/dhclient -d -q -sf /usr/libexec/nm-dhcp-helper -pf /var/run

ifconfig ens33 ip地址/24 临时性修改地址
ifconfig ens33:0 192.168.1.1/24 临时性虚拟网卡
ifconfig ens33:1 down 禁用(删除)虚拟网卡
ifconfig ens33 up 启用网卡
ifup ens33 启用网卡
ifdown ens33 禁用网卡

配置新的网卡步骤

添加一块新的网络适配器
在这里插入图片描述
重启

[root@localhost ~]# systemctl restart network

查看新的网卡

ens37: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.11.128  netmask 255.255.255.0  broadcast 192.168.11.255
        inet6 fe80::c322:ffca:27f8:d44b  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:23:15:6e  txqueuelen 1000  (Ethernet)
        RX packets 40  bytes 3549 (3.4 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 33  bytes 5683 (5.5 KiB)

进入接口进行配置

vim /etc/sysconfig/network-scripts/ifcfg-ens37

TYPE=Ethernet
BOOTPROTO=none
NAME=ens37
DEVICE=ens37
ONBOOT=yes
IPADDR=192.168.11.10
NETMASK=255.255.255.0
GATEWAY=192.168.12.2
DNS1=114.114.114.114

重启后查看

ens37: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.11.10  netmask 255.255.255.0  broadcast 12.0.0.255

检查能否ping通

C:\Users\Administrator>ping 192.168.11.10

正在 Ping 192.168.11.10 具有 32 字节的数据:
来自 192.168.11.10 的回复: 字节=32 时间<1ms TTL=64
来自 192.168.11.10 的回复: 字节=32 时间=1ms TTL=64
来自 192.168.11.10 的回复: 字节=32 时间<1ms TTL=64
来自 192.168.11.10 的回复: 字节=32 时间<1ms TTL=64

192.168.11.10 的 Ping 统计信息:
    数据包: 已发送 = 4,已接收 = 4,丢失 = 0 (0% 丢失),
往返行程的估计时间(以毫秒为单位):
    最短 = 0ms,最长 = 1ms,平均 = 0ms

网络探测工具

ping
由于输入ping会不停的ping,可以指定次数和超时时间

[root@localhost ~]# ping -c 2 192.168.11.10
PING 192.168.11.10 (192.168.11.10) 56(84) bytes of data.
64 bytes from 192.168.11.10: icmp_seq=1 ttl=64 time=0.046 ms
64 bytes from 192.168.11.10: icmp_seq=2 ttl=64 time=0.071 ms

--- 192.168.11.10 ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1002ms
rtt min/avg/max/mdev = 0.046/0.058/0.071/0.014 ms

[root@localhost ~]# ping -w 3 192.168.11.10
PING 192.168.11.10 (192.168.11.10) 56(84) bytes of data.
64 bytes from 192.168.11.10: icmp_seq=1 ttl=64 time=0.056 ms
64 bytes from 192.168.11.10: icmp_seq=2 ttl=64 time=0.040 ms
64 bytes from 192.168.11.10: icmp_seq=3 ttl=64 time=0.076 ms

--- 192.168.11.10 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2003ms
rtt min/avg/max/mdev = 0.040/0.057/0.076/0.016 ms

[root@localhost ~]# ping -i 3 192.168.11.10
[root@localhost ~]# ping -i 0.5 - c 5 192.168.11.10

路由追踪traceroute

[root@localhost ~]# traceroute 192.168.11.10
traceroute to 192.168.11.10 (192.168.11.10), 30 hops max, 60 byte packets
 1  localhost.localdomain (192.168.11.10)  0.039 ms  0.010 ms  0.009 ms

查路由表route
查本机路由表

[root@localhost ~]# route
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface

同样的命令还有:route -n、ip route

手动做静态路由
route add -net 192.168.2.0 netmask 255.255.255.0 gw 192.168.11.2

[root@localhost ~]# route add -net 192.168.2.0 netmask 255.255.255.0 gw 192.168.11.2
[root@localhost ~]# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         192.168.71.2    0.0.0.0         UG    100    0        0 ens33
0.0.0.0         192.168.12.2    0.0.0.0         UG    101    0        0 ens37
192.168.2.0     192.168.11.2    255.255.255.0   UG    0      0        0 ens37

删除某个目标网段
route del -net 192.168.2.0/24

增加默认路由
route add default gw IP
删除
route del default gw IP

hostname主机名称配置

临时改主机名
hostname 名称
永久改名(进编辑器改)
vim /etc/hostname
hostname ctl set-hostname 名称 (立即生效)

显示本机ip
hostname -i

[root@localhost ~]# hostname -i
fe80::c48d:a362:6194:6ca4%ens33 fe80::20c:29ff:fe23:156e%ens37 192.168.71.130 192.168.122.1 192.168.11.10

查看环境变量
echo $HOSTNAME

netstat查看端口连接状态
netstat -a 查看端口所有状态
-l 查看监听状态
-n 以数字显示
-p 显示PID
-t 查看TCP协议连接
-u 查看UDP协议连接
-r 查看路由表

“ss 也可以查看,ss比netstat显示的速度更快”

看并发量(n快s慢)
time netstat -ant | grep EST | wc -l
time ss -o state established | wc -l

[root@localhost ~]# time netstat -ant | grep EST | wc -l
0

real	0m0.002s
user	0m0.002s
sys	0m0.003s
[root@localhost ~]# time ss -o state established | wc -l
736

real	0m0.046s
user	0m0.000s
sys	0m0.009s

本地用户映射文件

cat /etc/hosts文件
保存主机名与IP地址的映射记录

hosts文件和DNS服务器的比较
默认情况下,系统首先从hosts文件查找解析记录
hosts文件之多当前的主机有效
hosts文件可减少DNS查询过程,从而加快访问速度

nslookup\host\dig 域名解析
dig …更详细解析

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值