自学内容网 自学内容网

网络属性及相关配置常用命令-上篇

网络属性及相关配置

网卡名字

rocky8|openEuler

ip a |egrep 'mtu|scrope'

cd /etc/sysconfig/network-scripts
mv ifcfg-ens160 ifcfg-eth0
sed -i 's/ens160/eth0/g' ifcfg-eth0

vim /etc/default/grub#grub是启动配置文件
GRUB_CMDLINE_LINUX="... net.ifnames=0 biosdevname=0"

grub2-mkconfig -o /etc/grub2.cfg;reboot #重读配置文件并重启

ip a|egrep 'mtu|scope'

rocky9

ip a|egrep 'mtu|scope|ether'
cat /sys/class/net/ens160/type #查看要修改的设备类型ID

mv /etc/NetworkManager/system-connections/{ens160.nmconnection,eth0.nmconnection}
sed -i 's/ens160/eth0/g' /etc/NetworkManager/system-connections/eth0.nmconnection
cat /etc/NetworkManager/system-connections/eth0.nmconnection

vim /etc/udev/rules.d/70-persistent-net.rules
SUBSYSTEM=="net",ACTION=="add",ATTR{address}=="00:0c:29:b1:f4:54",ATTR{type}=="1",NAME="eth0"

vim /etc/default/grub
GRUB_CMDLINE_LINUX="... net.ifnames=0 biosdevname=0"

grub2-mkconfig -o /etc/grub2.cfg;reboot
ip a|egrep 'mtu|scope|etger'

ubuntu

ip a|egrep 'mtu|scope|etger'
ls /etc/netplan
chmod 600 /etc/netplan/50-cloud-init.yaml
vim /etc/netplan/50-cloud-init.yaml
network:
 version: 2
renderer: NetworkManager
         ethernets:
             eth0:
                 addresses:
                 - "10.0.0.13/24"
                 nameservers:
                     addresses:
                     - 10.0.0.2
                 routes:
                     - to: default
                     via: 10.0.0.2
             eth1:
             addresses:
             - "192.168.8.113/24"

vim /etc/default/grub
GRUB_CMDLINE_LINUX=" net.ifnames=0 biosdevname=0"

grub-mkconfig -o /boot/grub/grub.cfg;reboot
ip a|egrep 'mtu|scope|etger'

#临时修改网卡
ip link set ens160 down
ip link set ens160 name abc
ip link set abc up

定制网卡

openEuler

#添加一块NAT模式网卡
cd /etc/sysconfig/network-scripts
cp ifcfg-eth0 ifcfg-eth1
sed -i 's/eth0/eth1/g' ifcfg-eth1#继续vim更改IP地址
cat ifcfg-eth1
cat /etc/resolv.conf
nmcli connection
nmcli con down eth1
nmcli con reload
nmcli con up eth1

nmcli con
ip a s eth1 #ip address show eth1
cat /etc/resolv.conf
ping www.baidu.com

#centos系列网卡生效方法
#centos7,8
systemctl restart NetworkManager
#centos6及以前
service network restart

ubuntu

ip a
cat /etc/netplan/50-cloud-init.yaml
netplan apply
ip a s eth2

rocky9

ip a |grep mtu
vim /etc/udev/rules.d/70-persistent-net.rules
SUBSYSTEM=="net",ACTION=="add",ATTR{address}=="00:0c:29:b1:f4:54",ATTR{type}=="1",NAME="eth0"
SUBSYSTEM=="net",ACTION=="add",ATTR{address}=="00:0c:29:b1:f4:5e",ATTR{type}=="1",NAME="eth1"

cd /etc/NetworkManager/system-connections/
cp eth0.nmconnection eth1.nmconnection
sed -i 's/eth0/eth1/g' eth1.nmconnection #继续vim修改IP地址
cat eth1.nmconnection
reboot

立刻生效方法

# openEuler添加一块NAT模式网卡
ip a|tail -n3
nmcli con
cd /etc/NetworkManager/system-connections
nmcil device
nmcli device up ens256
nmcli device
ls
cat ens256.nmconnection
nmcli con down ens256
nmcli con reload
nmcli con up ens256
ip a s ens256

主机名

临时

hostname -a
hostname ubuntu-test
hostname
exec /bin/bash #立刻生效

echo nihao > name.txt
hostname -F name.txt
hostname

永久

hostnamectl status
cat /etc/hostname
hostnamectl hostname ubuntu-24
cat /etc/hostname
hostnamectl
exec /bin.bash

ifconfig

#临时修改网卡信息
ifconfig eth1 10.0.0.55/24
#清除网卡设备信息
ifconfig eth1 0.0.0.0
#启用和关闭网络设备
ifconfig eth1 down
ifconfig eth1 up

#创建网卡别名
ifconfig ens160:1 10.0.0.200/24 up
ifconfig ens160:1
#取消网卡别名
ifconfig ens160:1 down

route

route
route -n
route add -net/-host 172.20.100.90 gw 10.0.0.12 dev eth0
route add -net/-host 172.20.100.90 eth0
route del

netstat

netstat -tunlp

面试题;查看哪个程序在监听端口

netstat -tunlp|grep ":22"
ss -tunlp|grep ":22"
lsof -i:22

原文地址:https://blog.csdn.net/m0_73940847/article/details/143875003

免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!