0
点赞
收藏
分享

微信扫一扫

ubuntu修改IP地址方法

无愠色 2022-03-12 阅读 71

1、首先查看需要修改的网口名称,此处我需要修改的时"eth0"

nvidia@nvidia:~$ ifconfig 
can0: flags=193<UP,RUNNING,NOARP>  mtu 16
        unspec 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00  txqueuelen 10  (UNSPEC)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
        device interrupt 67  

docker0: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500
        inet 172.17.0.1  netmask 255.255.0.0  broadcast 172.17.255.255
        ether 02:42:3e:81:5a:b0  txqueuelen 0  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.102.201  netmask 255.255.255.0  broadcast 192.168.102.255
        inet6 fe80::204:4bff:fecc:762  prefixlen 64  scopeid 0x20<link>
        ether 00:04:4b:cc:07:62  txqueuelen 1000  (Ethernet)
        RX packets 17762  bytes 2607796 (2.6 MB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 887  bytes 111758 (111.7 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
        device interrupt 40  

eth1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 64512
        inet 192.168.3.2  netmask 255.255.255.0  broadcast 192.168.3.255
        inet6 fe80::a42d:fdff:fe7d:5e54  prefixlen 64  scopeid 0x20<link>
        ether a6:2d:fd:7d:5e:54  txqueuelen 1000  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1  (Local Loopback)
        RX packets 281  bytes 546931 (546.9 KB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 281  bytes 546931 (546.9 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

rndis0: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500
        ether b6:38:30:54:58:f5  txqueuelen 1000  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

usb0: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500
        ether b6:38:30:54:58:f7  txqueuelen 1000  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

1、然后打开interfaces文件,修改相应的IP地址

sudo vi /etc/network/interfaces

2、interfaces内容如下图所示

# interfaces(5) file used by ifup(8) and ifdown(8)
# Include files from /etc/network/interfaces.d:
source-directory /etc/network/interfaces.d
auto lo
iface lo inet loopback

auto eth0
iface eth0 inet static    ## 设置静态IP
address 192.168.102.201  ## 修改此处为需要的IP地址
netmask 255.255.255.0

## DNS服务器
dns-nameserver 119.29.29.29
dns-nameserver 8.8.8.8
dns-nameserver 114.114.114.114

up route add default gw 192.168.102.1 ## 在静态IP地址下,保证网关在同一网段内

auto eth1
iface eth1 inet static
address 192.168.3.2
netmask 255.255.255.0

需要注意的是:

1、如果你不知道对端网口的网段,那么可以设置成动态IP,但是在不知道具体IP地址的情况下,无法进行远程登录。设置eth0为动态IP的方法如下所示:

# interfaces(5) file used by ifup(8) and ifdown(8)
# Include files from /etc/network/interfaces.d:
source-directory /etc/network/interfaces.d
auto lo
iface lo inet loopback

auto eth0
iface eth0 inet dhcp ## 设置动态IP

auto eth1
iface eth1 inet static
address 192.168.3.2
netmask 255.255.255.0

2、当设置完网络后,重启网络

sudo /etc/init.d/networking restart 

3、重启系统

sudo reboot
举报

相关推荐

0 条评论