centos7設定靜態ip

2021-08-11 06:29:56 字數 2123 閱讀 4275

1、編輯 ifcfg-eth0 檔案,vim 最小化安裝時沒有被安裝,需要自行安裝不描述。

eth0為本例使用的,你的不一定是eth0

[plain]view plain

copy

# vim /etc/sysconfig/network-scripts/ifcfg-eth0  

2、修改如下內容

[plain]view plain

copy

bootproto="static" #dhcp改為static   

onboot="yes" #開機啟用本配置  

ipaddr=192.168.7.106 #靜態ip  

gateway=192.168.7.1 #預設閘道器  

netmask=255.255.255.0 #子網掩碼  

dns1=192.168.7.1 #dns 配置  

3、修改後效果

[plain]view plain

copy

# ]# cat /etc/sysconfig/network-scripts/ifcfg-eth0  

hwaddr="00:15:5d:07:f1:02"  

type="ethernet"  

bootproto="static" #dhcp改為static   

defroute="yes"  

peerdns="yes"  

peerroutes="yes"  

ipv4_failure_fatal="no"  

ipv6init="yes"  

ipv6_autoconf="yes"  

ipv6_defroute="yes"  

ipv6_peerdns="yes"  

ipv6_peerroutes="yes"  

ipv6_failure_fatal="no"  

name="eth0"  

uuid="bb3a302d-dc46-461a-881e-d46cafd0eb71"  

onboot="yes" #開機啟用本配置  

ipaddr=192.168.7.106 #靜態ip  

gateway=192.168.7.1 #預設閘道器  

netmask=255.255.255.0 #子網掩碼  

dns1=192.168.7.1 #dns 配置  

4、重啟下網路服務

[plain]view plain

copy

# service network restart  

5、檢視改動後的效果,centois 7 不再使用 ifconfig 而是用 ip 命令檢視網路資訊。

[plain]view plain

copy

# ip addr  

1: lo: mtu 65536 qdisc noqueue state unknown   

link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00  

inet 127.0.0.1/8 scope host lo  

valid_lft forever preferred_lft forever  

inet6 ::1/128 scope host   

valid_lft forever preferred_lft forever  

2: eth0: 

mtu 1500 qdisc pfifo_fast state unknown qlen 1000  

link/ether 00:15:5d:07:f1:02 brd ff:ff:ff:ff:ff:ff  

inet 192.168.7.106/24 brd 192.168.7.255 scope global eth0  

valid_lft forever preferred_lft forever  

inet6 fe80::215:5dff:fe07:f102/64 scope link   

valid_lft forever preferred_lft forever  

Centos 7 靜態IP設定

在做專案時由於公司區域網採用自動獲取 的方式,導到每次伺服器重啟主機 都會變化。為了解決這個問題,我參考了的文章然後根據自己的情況設定靜態ip解決了這個問題,處理方式如下 device eth0 描述網絡卡對應的裝置別名,例如ifcfg eth0的檔案中它為eth0 bootproto static...

Centos7設定靜態IP

bootproto static dhcp改為static 修改 onboot yes 開機啟用本配置,一般在最後一行 修改 ipaddr 192.168.1.132 靜態ip 增加 netmask 255.255.255.0 子網掩碼 增加 nm controlled no表示該介面將通過該配置檔...

CentOs7靜態ip設定

修改網絡卡配置檔案 操作前先備份一下該檔案 etc sysconfig network scripts ifcfg ens33 如下 注 ifcfg ens33 對應自己的網絡卡名稱,不同網絡卡這個檔案字尾是不同的,如 ifcfg xxtype ethernet bootproto static d...