centos7 設定靜態IP

2022-08-23 11:12:09 字數 4587 閱讀 5709

centos7 設定靜態ip

#######一、查詢配置檔案(/etc/sysconfig/network-scripts)

[root@bogon network-scripts]# ll

總用量 232

-rw-r--r--. 1 root root 366 6月 7 10:39 ifcfg-eth0

-rw-r--r--. 1 root root 254 1月 3 00:29 ifcfg-lo

lrwxrwxrwx. 1 root root 24 6月 7 10:17 ifdown -> ../../../usr/sbin/ifdown

-rwxr-xr-x. 1 root root 654 1月 3 00:29 ifdown-bnep

-rwxr-xr-x. 1 root root 6569 1月 3 00:29 ifdown-eth

-rwxr-xr-x. 1 root root 781 1月 3 00:29 ifdown-ippp

-rwxr-xr-x. 1 root root 4540 1月 3 00:29 ifdown-ipv6

lrwxrwxrwx. 1 root root 11 6月 7 10:17 ifdown-isdn -> ifdown-ippp

-rwxr-xr-x. 1 root root 2102 1月 3 00:29 ifdown-post

-rwxr-xr-x. 1 root root 1068 1月 3 00:29 ifdown-ppp

-rwxr-xr-x. 1 root root 870 1月 3 00:29 ifdown-routes

-rwxr-xr-x. 1 root root 1456 1月 3 00:29 ifdown-sit

-rwxr-xr-x. 1 root root 1621 3月 18 2017 ifdown-team

-rwxr-xr-x. 1 root root 1556 3月 18 2017 ifdown-teamport

-rwxr-xr-x. 1 root root 1462 1月 3 00:29 ifdown-tunnel

lrwxrwxrwx. 1 root root 22 6月 7 10:17 ifup -> ../../../usr/sbin/ifup

-rwxr-xr-x. 1 root root 12415 1月 3 00:29 ifup-aliases

-rwxr-xr-x. 1 root root 910 1月 3 00:29 ifup-bnep

-rwxr-xr-x. 1 root root 13442 1月 3 00:29 ifup-eth

-rwxr-xr-x. 1 root root 12075 1月 3 00:29 ifup-ippp

-rwxr-xr-x. 1 root root 11893 1月 3 00:29 ifup-ipv6

lrwxrwxrwx. 1 root root 9 6月 7 10:17 ifup-isdn -> ifup-ippp

-rwxr-xr-x. 1 root root 650 1月 3 00:29 ifup-plip

-rwxr-xr-x. 1 root root 1064 1月 3 00:29 ifup-plusb

-rwxr-xr-x. 1 root root 4981 1月 3 00:29 ifup-post

-rwxr-xr-x. 1 root root 4154 1月 3 00:29 ifup-ppp

-rwxr-xr-x. 1 root root 2001 1月 3 00:29 ifup-routes

-rwxr-xr-x. 1 root root 3303 1月 3 00:29 ifup-sit

-rwxr-xr-x. 1 root root 1755 3月 18 2017 ifup-team

-rwxr-xr-x. 1 root root 1876 3月 18 2017 ifup-teamport

-rwxr-xr-x. 1 root root 2711 1月 3 00:29 ifup-tunnel

-rwxr-xr-x. 1 root root 1836 1月 3 00:29 ifup-wireless

-rwxr-xr-x. 1 root root 5419 1月 3 00:29 init.ipv6-global

-rw-r--r--. 1 root root 19948 1月 3 00:29 network-functions

-rw-r--r--. 1 root root 31027 1月 3 00:29 network-functions-ipv6

二、備份網絡卡檔案
[root@bogon network-scripts]# cp ifcfg-eth0 ifcfg-eth0.bak
三、修改配置檔案為靜態ip
[root@bogon network-scripts]# vi ifcfg-eth0

修改後內容如下:

type=ethernet

proxy_method=none

browser_only=no

bootproto=static

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=eth0

uuid=a81aa960-d8db-40f3-8a3a-c430b1984c80

device=eth0

onboot=yes

ipaddr=10.211.55.10

netmask=255.255.255.0

network=10.211.55.1

dns1=10.211.55.1

四、修改閘道器配置檔案(/etc/sysconfig/network)
[root@bogon sysconfig]# vi network

內容如下:

# created by anaconda

networking=yes

networking_ipv6=no

gateway=10.211.55.1

五、重啟網絡卡
[root@bogon sysconfig]# systemctl restart network
六、檢視ip
[root@bogon sysconfig]# ip addr

1: lo: mtu 65536 qdisc noqueue state unknown group default qlen 1000

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 up group default qlen 1000

link/ether 00:1c:42:3f:bb:6f brd ff:ff:ff:ff:ff:ff

inet 10.211.55.10/24 brd 10.211.55.255 scope global noprefixroute eth0

valid_lft forever preferred_lft forever

inet6 fdb2:2c26:f4e4:0:21c:42ff:fe3f:bb6f/64 scope global mngtmpaddr dynamic

valid_lft 2591594sec preferred_lft 604394sec

inet6 fe80::21c:42ff:fe3f:bb6f/64 scope link

valid_lft forever preferred_lft forever

七、檢視路由
[root@bogon sysconfig]# ip route

default via 10.211.55.1 dev eth0 proto static metric 100

10.211.55.0/24 dev eth0 proto kernel scope link src 10.211.55.10 metric 100

注意事項
剛裝完機器不知道我的ip和閘道器模式為多少?

1.設定網絡卡

bootproto=dhcp

onboot=yes

2.重啟後執行第七步檢視路由命令,即可知道當前的ip位址和預設的閘道器位址。

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...