配置靜態IP

2022-08-01 10:09:12 字數 2339 閱讀 9023

一、安裝centos虛擬機器

二、檢查防火牆是否開啟,如果開啟我們把它關了並設定禁止開機自啟動

# service firewalld status   ---檢查防火牆服務狀態

# systemctl stop firewalld   ---停止執行防火牆

# systemctl disable firewalld ---禁用開機自啟動

# service firewalld status ---再次檢查

三、關閉selinux

1 # vim /etc/selinux/config   ---編輯這個檔案

編輯完了之後儲存退出,使用reboot重啟機器

四、檢視自己的dns和閘道器位址

# cat /etc/resolv.conf   ---nameserver後面就是dns和閘道器

或者使用以下命令檢視閘道器:

# netstat -rn ---gateway就是閘道器

# cat /etc/sysconfig/network ---檢視自定義閘道器,預設為空

五、配置靜態ip位址

a. 先進入network-scripts目錄下檢視自己的網絡卡檔案(我這裡是ifcfg-ens32)

# cd /etc/sysconfig/network-scripts   ---檢視網絡卡檔案

# ls ---ifcfg-ens**這個就是

b. 編輯ifcfg-ens32網絡卡檔案

# vim ifcfg-ens32   ---編輯網絡卡檔案,新增以下內容

type="ethernet"

proxy_method="none"

browser_only="no"

#bootproto="dhcp" ---先把這裡注釋了也可以刪掉

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="ens32"

uuid="25f5a8bf-fba8-4889-b9b1-42efacf50c5a"

device="ens32"

onboot="yes" ---要保證這裡是yes

# 設定為靜態ip,預設為dhcp

bootproto="static"

# 你要設定的靜態ip位址

ipaddr="192.168.*.*"

# 子網掩碼

netmask="255.255.255.0"

# 你的閘道器

gateway=""

# 你的dns伺服器位址

六、編輯network檔案

a. 編輯network檔案,在檔案中新增以下內容

# vim /etc/sysconfig/network   ---編輯network檔案,在檔案中新增以下內容

# created by anaconda

networking=yes

# getaway填你的閘道器位址

b. 重啟你的network服務

# service network restart
c. ping一下外網,看看能不能通,能通代表配置成功了,不能通再去看看步驟,哪個環節出問題了

七、參考文章

linux配置靜態IP

vi etc sysconfig network scripts ifcfg eth0針對特定的網絡卡進行設定 type ethernet bootproto static 啟動型別 靜態 預設dhcp defroute yes ipv4 failure fatal yes ipv6init no ...

redhat靜態Ip配置

依次修改以下三個檔案 etc sysconfig network etc sysconfig network scripts ifcfg eth0 etc resolv.conf 1.etc sysconfig network networking yes networking ipv6 no ho...

Linux 配置靜態IP

在新安裝的linux系統命令行下,敲入 ifconfig,顯示如下介面。上面這張圖顯示網絡卡沒有啟動,那麼我們敲入 ifup eth0啟動網絡卡。網絡卡啟動後,我們可以看出,ip位址和閘道器等其他資訊都已經出現。但是我們需要的是靜態ip,即不隨著時間改變而改變的ip位址。首先我們要知道我們的閘道器位...