Skip to content

linux 网络学习

仲灏2023-09-17约 1 分钟

查看当前 ip 地址

shell
ip addr show

ifconfig

修改网卡配置文件:

设置为固定 ip.

bash
# vi /etc/sysconfig/network-scripts/ifcfg-enp0s3 # 不同的网卡名臣可能不同

使网卡配置生效

重启网络服务。后查看 ip 是否与分配的相同。

bash
# service network restart
# ip addr show

ping 以下网络,检查网络连接状态。

css
# ping -c4 www.baidu.com

验证网络是否联通.

css
ping 10.1.1.1

使用 nmcli 命令查看一下网络设置:

shell
[root@localhost etc]# nmcli connection show
NAME             UUID                                  TYPE      DEVICE          
ens192           1b62cf76-140c-452e-9424-9300026bd22a  ethernet  ens192          
br-7e23d6219963  6cb9e11b-f4aa-43d4-b590-339d22ff6fb7  bridge    br-7e23d6219963

该命令会返回 4 列数据. 分别是 NAME(联网代号), UUID(识别码), TYPE网卡类型, DEVICE(网卡名称).

查看指定网卡的信息:

dart
nmcli connection show 联网代号

查看IPv6地址

shell
`ip addr show ens192 | grep "inet6.*global" | awk '{print $2}' | awk -F"/" '{print $1}'` || die "$ipv6"

ip addr | grep "inet6.*global" | grep -v "deprecated" | awk '{print $2}' | awk -F"/" '{print $1}' | sed -n '1,1p'

案例:

自动映射域名:

ddns:https://github.com/jeessy2/ddns-go