Linux之网络配置
ifconfig命令
查看或设定网络接口
ifconfig eth0 ip/24 设定网络
ifconfig eth0 down 关闭网络
ifconfig eth0 up 开启网络
测试
ifconfig

ifconfig eth0 ip/24 设定网络

ifconfig eth0 down 关闭网络

ifconfig eth0 up 开启网络

ip addr
检测或设定网络接口
ip addr show device 查看
ip addr del dev eth0 ip/24 删除
ip addr flush eth0 全部删除
ip addr add ip/24 dev device 设定
测试
ip addr

ip addr show eth0

ip addr add 172.25.254.200/24 dev eth0

ip addr flush eth0
ip addr add 172.25.254.200/24 dev eth0

IP 设定方式
1.图形方式
nm-connection-editor
2.nmtui(无图形界面设定ip)
1)创建连接

2)添加一个网络

3)选择以太网

4)修改名字、添加ip

5)eth1添加完成

3.命令方式设定IP
nmcli device connect eth0 ##启用eth0网卡
nmcli device disconnect eth0 ##关闭eth0网卡
nmcli device show eth0 ##查看网卡信息
nmcli device status eth0 ##查看网卡服务接口信息
注意:nmcli 前提是NetworkManager必须开启
测试
nmcli device connect eth0 ##启用eth0网卡
nmcli device disconnect eth0 ##关闭eth0网卡

nmcli device show eth0 ##查看网卡信息

nmcli device status eth0 ##查看网卡服务接口信息

nmcli connection show ##显示网络信息
nmcli connection down eth0 ##关闭eth0
nmcli connection up eth0 ##开启eth0
nmcli connection delete eth0 ##删除eth0
nmcli connection add type ethernet con-name eth0 ifname eth0 ip4 1.1.1.224/24 ##添加一个名字为eth0,ip为1.1.1.224,子网掩码为255.255.255.0的网络
测试
nmcli connection down westos 关闭

nmcli connection up westos 开启

nmcli connection delete westos 删除

nmcli connection add type ethernet con-name westos ifname eth0 ip4 1.1.1.224/24

上面ip设定方式也是临时的,虚拟机重启后就消失了
nmcli connection modify westos ipv4.method auto 修改为动态网络
nmcli connection modify westos ipv4.method manual 修改为静态网络
nmcli connection modify westos ipv4.addresses 172.25.254.200/24 修改ip和子网掩码为172.25.254.200/24
测试
nmcli connection modify westos ipv4.method auto 修改为动态网络

管理网络配置文件
vim /etc/sysconfig/network-scripts/
ifcfg-xxxx ##网卡文件
DEVICE=**** ##****为网卡设备名称
BOOTPROTO=dhcp/static/none ##设定工作方式(动态/静态/无)
ONBOOT=yes ##网络服务开启时自动激活网卡
IPADDR= ##ip地址
PREFIX=24 ##子网掩码设置形式
NETMASK=255.255.255.0 ##子网掩码设置形式
NAME= ##接口名称(可以不写)
TYPE=Ethernet ##网卡类型(以太网)(可以不写)
测试
1.设定静态网络


2.在同一块网卡上设置两个IP


3.设置动态网络

