Skip to content

Commit 39581ed

Browse files
committed
docs(vm-linux-static-ip): update post
1 parent 334e6c4 commit 39581ed

File tree

1 file changed

+305
-6
lines changed

1 file changed

+305
-6
lines changed

post/other/vm-linux-static-ip.md

Lines changed: 305 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ vmware 总是给虚拟机变化 ip,经常连接出错,索性固定一下 ip
77

88
## 在 Vmware 中更改网关和网段
99

10+
> 这个一般情况下是不需要改的,VM 默认的就是
11+
1012
点击【编辑】> 点击【虚拟网络编辑器】
1113

1214
![image](https://jsonq.top/cdn-static/2025/04/27/202505032051190.png)
@@ -15,15 +17,15 @@ vmware 总是给虚拟机变化 ip,经常连接出错,索性固定一下 ip
1517

1618
![image](https://jsonq.top/cdn-static/2025/05/03/202505032055735.png)
1719

18-
更改【子网IP】> 更改【子网掩码】> 点击【NAT设置
20+
更改【子网 IP】> 更改【子网掩码】> 点击【NAT 设置
1921

20-
> 子网IP中的 88 可以根据自己需要修改,不改也可以
22+
> 子网 IP 中的 88 可以根据自己需要修改,不改也可以
2123
>
2224
> **子网掩码必须为 `255.255.255.0`**
2325
2426
![image](https://jsonq.top/cdn-static/2025/05/03/202505032057923.png)
2527

26-
更改【网关IP】> 点击【确定】
28+
更改【网关 IP】> 点击【确定】
2729

2830
> 这里直接点击 【确定】 即可。
2931
@@ -33,29 +35,326 @@ vmware 总是给虚拟机变化 ip,经常连接出错,索性固定一下 ip
3335

3436
进入 Linux 系统,编辑配置文件
3537

38+
**Centos 7 的配置文件一般在 `/etc/sysconfig/network-scripts` 下,Centos 9 的在 `/etc/NetworkManager/system-connections`,具体的配置名可使用 `ip addr` 查看就行**
39+
40+
### Centos 7
41+
3642
```bash
3743
vi /etc/sysconfig/network-scripts/ifcfg-ens33
3844
```
3945

4046
1.`BOOTPROTO="dncp"` 改为 `BOOTPROTO="static"`
4147
2. 新增下图的四个配置
4248

43-
- dhcp:表示自动获取IP
44-
- static:静态IP
45-
- IPADDR:IP地址,就是常规访问的ip,必须保证在前面所设置的 192.168.xx.0 ~ 192.168.xx.254 之间
49+
- dhcp:表示自动获取 IP
50+
- static:静态 IP
51+
- IPADDR:IP 地址,就是常规访问的 ip,必须保证在前面所设置的 192.168.xx.0 ~ 192.168.xx.254 之间
4652
- NETMASK:子网掩码,必须为 255.255.255.0
4753
- GATEWAY:网关,与刚才 NAT 设置中的网关 IP 保持一致
4854
- DNS1:域名解析服务器,与网关保持一致即可
4955

5056
![image](https://jsonq.top/cdn-static/2025/05/03/202505032105980.png)
5157

58+
### Centos 9
59+
60+
```bash
61+
vi /etc/NetworkManager/system-connections/es160.nmconnection
62+
```
63+
64+
```bash
65+
[connection]
66+
id=ens160
67+
uuid=5d896bda-c62a-3eb1-bc29-7c031232db86
68+
type=ethernet
69+
autoconnect-priority=-999
70+
interface-name=ens160
71+
timestamp=1670979495
72+
73+
[ethernet]
74+
75+
[ipv4]
76+
# mehod=auto # 可以注释掉也可以直接改
77+
method=manual # 改成manual(意思是设置手动模式)
78+
address1=192.168.192.128/24,192.168.192.2 # 静态ip/子网掩码长度(255.255.255.0 长度为 24), 网关
79+
dns=114.114.114.114,8.8.8.8 # dns地址,用 , 隔开
80+
81+
[ipv6]
82+
addr-gen-mode=eui64
83+
method=auto
84+
85+
[proxy]
86+
```
87+
5288
## 重启网卡服务
5389

5490
```bash
91+
# Centos 7
5592
systemctl stop network
5693
systemctl start network
5794

95+
# Centos 9
96+
nmcli c reload ens160 # 或 systemctl restart NetworkManager.service
97+
5898
ip addr
5999
```
60100

61101
![image](https://jsonq.top/cdn-static/2025/05/03/202505032110019.png)
102+
103+
## 设置镜像 yum 源
104+
105+
### Centos 7
106+
107+
参照 https://www.cnblogs.com/kohler21/p/18331060 即可
108+
109+
### Centos 9
110+
111+
先找到配置 yum 源的文件
112+
113+
```bash
114+
cd /etc/yum.repos.d
115+
ls
116+
```
117+
118+
拷贝两个文件以防万一
119+
120+
```bash
121+
cp /etc/yum.repos.d/centos.repo /etc/yum.repos.d/centos.repo.backup-20250827
122+
cp /etc/yum.repos.d/centos-addons.repo /etc/yum.repos.d/centos-addons.repo.backup-20250827
123+
```
124+
125+
修改 centos.repo
126+
127+
```bash
128+
[baseos]
129+
name=CentOS Stream $releasever - BaseOS
130+
baseurl=https://mirrors.aliyun.com/centos-stream/$stream/BaseOS/$basearch/os/
131+
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
132+
gpgcheck=1
133+
repo_gpgcheck=0
134+
metadata_expire=6h
135+
countme=1
136+
enabled=1
137+
138+
[baseos-debug]
139+
name=CentOS Stream $releasever - BaseOS - Debug
140+
baseurl=https://mirrors.aliyun.com/centos-stream/$stream/BaseOS/$basearch/debug/tree/
141+
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
142+
gpgcheck=1
143+
repo_gpgcheck=0
144+
metadata_expire=6h
145+
enabled=0
146+
147+
[baseos-source]
148+
name=CentOS Stream $releasever - BaseOS - Source
149+
baseurl=https://mirrors.aliyun.com/centos-stream/$stream/BaseOS/source/tree/
150+
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
151+
gpgcheck=1
152+
repo_gpgcheck=0
153+
metadata_expire=6h
154+
enabled=0
155+
156+
[appstream]
157+
name=CentOS Stream $releasever - AppStream
158+
baseurl=https://mirrors.aliyun.com/centos-stream/$stream/AppStream/$basearch/os/
159+
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
160+
gpgcheck=1
161+
repo_gpgcheck=0
162+
metadata_expire=6h
163+
countme=1
164+
enabled=1
165+
166+
[appstream-debug]
167+
name=CentOS Stream $releasever - AppStream - Debug
168+
baseurl=https://mirrors.aliyun.com/centos-stream/$stream/AppStream/$basearch/debug/tree/
169+
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
170+
gpgcheck=1
171+
repo_gpgcheck=0
172+
metadata_expire=6h
173+
enabled=0
174+
175+
[appstream-source]
176+
name=CentOS Stream $releasever - AppStream - Source
177+
baseurl=https://mirrors.aliyun.com/centos-stream/$stream/AppStream/$basearch/debug/tree/
178+
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
179+
gpgcheck=1
180+
repo_gpgcheck=0
181+
metadata_expire=6h
182+
enabled=0
183+
184+
[crb]
185+
name=CentOS Stream $releasever - CRB
186+
baseurl=https://mirrors.aliyun.com/centos-stream/$stream/CRB/$basearch/os/
187+
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
188+
gpgcheck=1
189+
repo_gpgcheck=0
190+
metadata_expire=6h
191+
countme=1
192+
enabled=0
193+
194+
[crb-debug]
195+
name=CentOS Stream $releasever - CRB - Debug
196+
baseurl=https://mirrors.aliyun.com/centos-stream/$stream/CRB/$basearch/debug/tree/
197+
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
198+
gpgcheck=1
199+
repo_gpgcheck=0
200+
metadata_expire=6h
201+
enabled=0
202+
203+
[crb-source]
204+
name=CentOS Stream $releasever - CRB - Source
205+
baseurl=https://mirrors.aliyun.com/centos-stream/$stream/CRB/source/tree/
206+
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
207+
gpgcheck=1
208+
repo_gpgcheck=0
209+
metadata_expire=6h
210+
enabled=0
211+
```
212+
213+
修改 centos-addons.repo
214+
215+
```bash
216+
[highavailability]
217+
name=CentOS Stream $releasever - HighAvailability
218+
baseurl=http://mirrors.aliyun.com/centos-stream/$stream/HighAvailability/$basearch/os/
219+
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
220+
gpgcheck=1
221+
repo_gpgcheck=0
222+
metadata_expire=6h
223+
countme=1
224+
enabled=0
225+
226+
[highavailability-debug]
227+
name=CentOS Stream $releasever - HighAvailability - Debug
228+
baseurl=http://mirrors.aliyun.com/centos-stream/$stream/HighAvailability/$basearch/debug/tree/
229+
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
230+
gpgcheck=1
231+
repo_gpgcheck=0
232+
metadata_expire=6h
233+
enabled=0
234+
235+
[highavailability-source]
236+
name=CentOS Stream $releasever - HighAvailability - Source
237+
baseurl=http://mirrors.aliyun.com/centos-stream/$stream/HighAvailability/source/tree/
238+
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
239+
gpgcheck=1
240+
repo_gpgcheck=0
241+
metadata_expire=6h
242+
enabled=0
243+
244+
[nfv]
245+
name=CentOS Stream $releasever - NFV
246+
baseurl=http://mirrors.aliyun.com/centos-stream/$stream/NFV/$basearch/os/
247+
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
248+
gpgcheck=1
249+
repo_gpgcheck=0
250+
metadata_expire=6h
251+
countme=1
252+
enabled=0
253+
254+
[nfv-debug]
255+
name=CentOS Stream $releasever - NFV - Debug
256+
baseurl=http://mirrors.aliyun.com/centos-stream/$stream/NFV/$basearch/debug/tree/
257+
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
258+
gpgcheck=1
259+
repo_gpgcheck=0
260+
metadata_expire=6h
261+
enabled=0
262+
263+
[nfv-source]
264+
name=CentOS Stream $releasever - NFV - Source
265+
baseurl=http://mirrors.aliyun.com/centos-stream/$stream/NFV/source/tree/
266+
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
267+
gpgcheck=1
268+
repo_gpgcheck=0
269+
metadata_expire=6h
270+
enabled=0
271+
272+
[rt]
273+
name=CentOS Stream $releasever - RT
274+
baseurl=http://mirrors.aliyun.com/centos-stream/$stream/RT/$basearch/os/
275+
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
276+
gpgcheck=1
277+
repo_gpgcheck=0
278+
metadata_expire=6h
279+
countme=1
280+
enabled=0
281+
282+
[rt-debug]
283+
name=CentOS Stream $releasever - RT - Debug
284+
baseurl=http://mirrors.aliyun.com/centos-stream/$stream/RT/$basearch/debug/tree/
285+
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
286+
gpgcheck=1
287+
repo_gpgcheck=0
288+
metadata_expire=6h
289+
enabled=0
290+
291+
[rt-source]
292+
name=CentOS Stream $releasever - RT - Source
293+
baseurl=http://mirrors.aliyun.com/centos-stream/$stream/RT/source/tree/
294+
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
295+
gpgcheck=1
296+
repo_gpgcheck=0
297+
metadata_expire=6h
298+
enabled=0
299+
300+
[resilientstorage]
301+
name=CentOS Stream $releasever - ResilientStorage
302+
baseurl=http://mirrors.aliyun.com/centos-stream/$stream/ResilientStorage/$basearch/os/
303+
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
304+
gpgcheck=1
305+
repo_gpgcheck=0
306+
metadata_expire=6h
307+
countme=1
308+
enabled=0
309+
310+
[resilientstorage-debug]
311+
name=CentOS Stream $releasever - ResilientStorage - Debug
312+
baseurl=http://mirrors.aliyun.com/centos-stream/$stream/ResilientStorage/$basearch/debug/tree/
313+
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
314+
gpgcheck=1
315+
repo_gpgcheck=0
316+
metadata_expire=6h
317+
enabled=0
318+
319+
[resilientstorage-source]
320+
name=CentOS Stream $releasever - ResilientStorage - Source
321+
baseurl=http://mirrors.aliyun.com/centos-stream/$stream/ResilientStorage/source/tree/
322+
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
323+
gpgcheck=1
324+
repo_gpgcheck=0
325+
metadata_expire=6h
326+
enabled=0
327+
328+
[extras-common]
329+
name=CentOS Stream $releasever - Extras packages
330+
baseurl=http://mirrors.aliyun.com/centos-stream/SIGs/$stream/extras/$basearch/extras-common/
331+
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-SIG-Extras-SHA512
332+
gpgcheck=1
333+
repo_gpgcheck=0
334+
metadata_expire=6h
335+
countme=1
336+
enabled=1
337+
338+
[extras-common-source]
339+
name=CentOS Stream $releasever - Extras packages - Source
340+
baseurl=http://mirrors.aliyun.com/centos-stream/SIGs/$stream/extras/source/extras-common/
341+
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-SIG-Extras-SHA512
342+
gpgcheck=1
343+
repo_gpgcheck=0
344+
metadata_expire=6h
345+
enabled=0
346+
```
347+
348+
更新缓存
349+
350+
```bash
351+
yum makecache
352+
353+
yum update
354+
```
355+
356+
## VM 安装教程
357+
358+
https://blog.csdn.net/qq_45743985/article/details/121152504
359+
360+
网络的静态 ip 不随教程走

0 commit comments

Comments
 (0)