Linux修改IP位址

2021-08-21 10:46:49 字數 3357 閱讀 5131

1.檢視本機ip位址,自動獲取192.168.1.12,我們將它改為192.168.1.100的內網ip,將網絡卡改為橋接模式

[root@localhost ~]# ifconfig
enp0s3: flags=4163mtu 1500

inet 192.168.1.12 netmask 255.255.255.0 broadcast 192.168.1.255

inet6 fe80::9fcb:e79f:32bb:57a6 prefixlen 64 scopeid 0x20ether 08:00:27:8f:b7:2c txqueuelen 1000 (ethernet)

rx packets 3307 bytes 208431 (203.5 kib)

rx errors 0 dropped 0 overruns 0 frame 0

tx packets 392 bytes 31801 (31.0 kib)

tx errors 0 dropped 0 overruns 0 carrier 0 collisions 0

lo: flags=73mtu 65536

inet 127.0.0.1 netmask 255.0.0.0

inet6 ::1 prefixlen 128 scopeid 0x10loop txqueuelen 1000 (local loopback)

rx packets 68 bytes 5908 (5.7 kib)

rx errors 0 dropped 0 overruns 0 frame 0

tx packets 68 bytes 5908 (5.7 kib)

tx errors 0 dropped 0 overruns 0 carrier 0 collisions 0

網絡卡enp0s3

en:表示乙太網卡

p0s3:代表pci介面的物理位置為(0, 3), 其中橫座標代表bus,縱座標代表slot

2.進行ip位址的修改

[root@localhost ~]# vim /etc/sysconfig/network-scripts/ifcfg-enp0s3
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=enp0s3

uuid=f1f5f762-3838-4908-b8d7-e6866c62f508

device=enp0s3

onboot=yes

修改為:

type=ethernet

proxy_method=none

browser_only=no

#bootproto=dhcp

#added

bootproto=static

ipaddr=192.168.1.100

netmask=255.255.255.0

gateway=192.168.1.1

#end added

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

uuid=f1f5f762-3838-4908-b8d7-e6866c62f508

hwaddr=08:00:27:2e:c2:f8

device=enp0s3

onboot=yes

3.重啟reboot檢視是否更改

[root@localhost ~]# reboot

[root@localhost ~]# service network restart

4.使用ifconfig檢視ip位址是否改變

[root@localhost ~]# ifconfig
enp0s3: flags=4163mtu 1500

inet 192.168.1.100 netmask 255.255.255.0 broadcast 192.168.1.255

inet6 fe80::9fcb:e79f:32bb:57a6 prefixlen 64 scopeid 0x20ether 08:00:27:8f:b7:2c txqueuelen 1000 (ethernet)

rx packets 212 bytes 16235 (15.8 kib)

rx errors 0 dropped 0 overruns 0 frame 0

tx packets 73 bytes 14013 (13.6 kib)

tx errors 0 dropped 0 overruns 0 carrier 0 collisions 0

lo: flags=73mtu 65536

inet 127.0.0.1 netmask 255.0.0.0

inet6 ::1 prefixlen 128 scopeid 0x10loop txqueuelen 1000 (local loopback)

rx packets 196 bytes 17040 (16.6 kib)

rx errors 0 dropped 0 overruns 0 frame 0

tx packets 196 bytes 17040 (16.6 kib)

tx errors 0 dropped 0 overruns 0 carrier 0 collisions 0

5.可能會連不上外網,需要加上閘道器,才能上網

[root@localhost ~]# vim /etc/resolv.conf

; generated by /usr/sbin/dhclient-script

nameserver 192.168.1.1

search localdomain

linux 修改IP位址

一臨時修改 1.首先用ifconfig檢視網絡卡裝置標識,比如eth0。2.執行ifconfig eth0 ip mask。比如 ifconfig eth0 10.2.45.20 255.255.255.二永久修改 1.首先用ifconfig檢視網絡卡裝置標識,比如eth0。2.進入目錄 etc s...

linux 修改ip位址

設定linux ip位址 兩個步驟 1 修改配置檔案 etc sysconfig network script ifcfg etho 2 重啟網路服務或網絡卡 service network restart ifconfig eth0 down ifdown eth0 ifconfig eth0 u...

linux修改ip位址

臨時修改 合理的建立標題,有助於目錄的生成 1 臨時修改 重啟服務或者重啟系統後失效 ifconfig eth0 192.168.1.1 netmask 255.255.255.0 縮略 ifconfig eth0 192.168.1.1 eth0是第乙個網絡卡,eth1是第二個 2 永久修改 需要...