当前位置: 首页 > Linux

centos7固定IP地址

时间:2023-04-06 11:48:23 Linux

centos7固定IP地址centos7网络IP地址配置文件/etc/sysconfig/network-scripts首先查看当前网卡名称ifconfig[root@localhost]#ifconfigdocker0:flags=4163mtu1500inet172.17.0.1网络掩码255.255.0.0广播172.17.255.255inet6fe80::42:dff:fe04:70ebprefixlen64scopeid0x20ether02:42:0d:04:70:ebtxqueuelen0(以太网)RX数据包660bytes3611.5MiB)RX错误0dropped0overruns0frame0TXpackets997bytes272465(266.0KiB)TXerrors0dropped0overruns0carrier0collisions0ens33:flags=4163ether00:0c:29:1f:1d:a2txqueuelenX1packs1000(Ethernets)347.6KiB)RXerrors0dropped0overruns0frame0TXpackets2057bytes2644609(2.5MiB)TXerrors0dropped0overruns0carrier0collisions0lo:flags=73mtu65536inet127.0.0.1netmask255.0.0.0inet6::1prefixlen128scopeid0x10循环txqueuelen1000(本地环回)RX数据包0字节0(0.0B)RX错误0丢弃0溢出0帧0TX数据包0字节0(0.0B)TX错误0丢弃0溢出0载波0冲突0veth3af3ed4:flags=4163mtu1500inet6fe80::a4d2:2ff:fe1a:e6cdprefixlen64scopeid0x20ethera6:d2:02:1a:e6:cdtxqueuelen0(以太网)RXpackets0bytes0(0.0B)RXerrors0dropped0overruns0frame0TXpackets23bytes1873(1.8KiB)TXerrors0dropped0overruns0carrier0collisions0veth5705b61:flags=4163mtu1500inet6fe80::30c3:96ff:fe3c:5a0fprefixlen64scopeid0x20ether32:c3:96:3c:5a:0ftxqueuelen0(以太网)RX数据包0字节0(0.0B)RX错误0dropped0overruns0frame0TXpackets25bytes2133(2.0KiB)TXerrors0dropped0overruns0carrier0collisions0vethb48dd9e:flags=4163mtu1500inet6fe80::8493:b0ff:fe99:3410prefixlen64scopeid0x20ether86:93:b0:99:34:10txqueuelen0(以太网)RX数据包667字节1615377(1.5MiB)RX错误0丢弃0溢出0帧0TX数据包997字节272252(265.8KiB)TX错误0丢弃0超限0载体0冲突0virbr0:flags=4099mtu1500inet192.168.122.1netmask255.255.255.0broadcast192.168.122.255ether52:54:00:04:9d:27txqueuelen1000(Ethernet)RXpackets0bytes0(0.0B)RXerrors0dropped0overruns0frame0TXpackets0bytes0(0.0B)TXerrors0dropped0overruns0carrier0collisions0ens33网卡对应的配置文件是ifcfg-ens33,使用vim编辑如下[root@localhost]#vimifcfg-ens33TYPE="Ethernet"PROXY_METHOD="none"BROWSER_ONLY="no"BOOTPROTO="static"#使用静态IP地址,默认为dhcpIPADDR="192.168.241.100"#设置静态IP地址NETMASK="255.255.255.0"#子网掩码GATEWAY="192.168.241.2"#网关地址DNS1="192.168.241.2"#DNS服务器DEFROUTE="yes"IPV4_FAILURE_FATAL="no"IPV6INIT="yes"IPV6_AUTOCONF="yes"IPV6_DEFROUTE="yes"IPV6_FAILURE_FATAL="no"IPV6_ADDR_GEN_MODE="stable-privacy"NAME="ens33"UUID="95b614cd-79b0-4755-b08d-99f1cca7271b"DEVICE="ens33"ONBOOT="yes"#是否启用和重启网络服务设置静态IP地址[root@localhost]#servicenetworkrestart[root@localhost]#systemctlrestartnewwork.serviceother辅助查看本地网关[root@localhost]#route-nKernelIP路由表DestinationGatewaygenmask标志公制参考使用Iface184.82.152.960.0.0.0255.255.255.248U000eth0169.254.0.00.0.0.0255.255.0.0U000eth00.0.0.0184.82.152.970UG0.0.0eth0[root@localhost]#netstat-rnKernelIP路由表目标网关Genmask标志MSS窗口irttIface184.82.152.960.0.0.0255.255.255.248U000eth0169.254.0.00.0.0.0255.255.0.0U0000eth0.0.0.0184.82.152.970.0.0.0UG000eth0查看DNS[root@localhost]#cat/etc/resolv.conf配置hostname[root@localhost]#hostnamectlset-hostnamemini1