⑴ 如何在Ubuntu 15.10上为单个网卡设置多个IP地址
有时候你可能想在你的网卡上使用多个 IP 地址。遇到这种情况你会怎么办呢?买一个新的网卡并分配一个新的 IP?不,没有这个必要(至少在小型网络中)。现在我们可以在 Ubuntu 系统中为一个网卡分配多个 IP 地址。想知道怎么做到的?跟着我往下看,其实并不难。
这个方法也适用于 Debian 以及它的衍生版本。
临时添加 IP 地址
首先,让我们找到网卡的 IP 地址。在我的 Ubuntu 15.10 服务器版中,我只使用了一个网卡。
运行下面的命令找到 IP 地址:
sudoip addr
样例输出:
1: lo:<LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default
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: enp0s3:<BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP groupdefault qlen 1000
link/ether 08:00:27:2a:03:4b brd ff:ff:ff:ff:ff:ff
inet 192.168.1.103/24 brd 192.168.1.255 scope global enp0s3
valid_lft forever preferred_lft forever
inet6 fe80::a00:27ff:fe2a:34e/64 scope link
valid_lft forever preferred_lft forever
或
sudoifconfig
样例输出:
enp0s3 Link encap:EthernetHWaddr08:00:27:2a:03:4b
inet addr:192.168.1.103Bcast:192.168.1.255Mask:255.255.255.0
inet6 addr: fe80::a00:27ff:fe2a:34e/64Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500Metric:1
RX packets:186 errors:0 dropped:0 overruns:0 frame:0
TX packets:70 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:21872(21.8 KB) TX bytes:9666(9.6 KB)
lo Link encap:LocalLoopback
inet addr:127.0.0.1Mask:255.0.0.0
inet6 addr:::1/128Scope:Host
UP LOOPBACK RUNNING MTU:65536Metric:1
RX packets:217 errors:0 dropped:0 overruns:0 frame:0
TX packets:217 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:38793(38.7 KB) TX bytes:38793(38.7 KB)
正如你在上面输出中看到的,我的网卡名称是 enp0s3,它的 IP 地址是 192.168.1.103。
现在让我们来为网卡添加一个新的 IP 地址,例如说 192.168.1.104。
打开你的终端并运行下面的命令添加额外的 IP。
sudoip addr add 192.168.1.104/24 dev enp0s3
用命令检查是否启用了新的 IP:
sudoip address show enp0s3
样例输出:
2: enp0s3:<BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP groupdefault qlen 1000
link/ether 08:00:27:2a:03:4e brd ff:ff:ff:ff:ff:ff
inet 192.168.1.103/24 brd 192.168.1.255 scope global enp0s3
valid_lft forever preferred_lft forever
inet 192.168.1.104/24 scope global secondary enp0s3
valid_lft forever preferred_lft forever
inet6 fe80::a00:27ff:fe2a:34e/64 scope link
valid_lft forever preferred_lft forever
类似地,你可以添加任意数量的 IP 地址,只要你想要。
让我们 ping 一下这个 IP 地址验证一下。
sudoping192.168.1.104
样例输出
PING 192.168.1.104(192.168.1.104)56(84) bytes of data.
64 bytes from192.168.1.104: icmp_seq=1 ttl=64time=0.901 ms
64 bytes from192.168.1.104: icmp_seq=2 ttl=64time=0.571 ms
64 bytes from192.168.1.104: icmp_seq=3 ttl=64time=0.521 ms
64 bytes from192.168.1.104: icmp_seq=4 ttl=64time=0.524 ms
好极了,它能工作!
要删除 IP,只需要运行:
sudoip addr del192.168.1.104/24 dev enp0s3
再检查一下是否删除了 IP。
sudoip address show enp0s3
样例输出:
2: enp0s3:<BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP groupdefault qlen 1000
link/ether 08:00:27:2a:03:4e brd ff:ff:ff:ff:ff:ff
inet 192.168.1.103/24 brd 192.168.1.255 scope global enp0s3
valid_lft forever preferred_lft forever
inet6 fe80::a00:27ff:fe2a:34e/64 scope link
valid_lft forever preferred_lft forever
可以看到已经没有了!!
正如你所知,重启系统后这些设置会失效。那么怎么设置才能永久有效呢?这也很简单。
添加永久 IP 地址
Ubuntu 系统的网卡配置文件是 /etc/network/interfaces。
让我们来看看上面文件的具体内容。
sudocat/etc/network/interfaces
输出样例:
#Thisfile describes the network interfaces available on your system
#and how to activate them.Formore information, see interfaces(5).
source /etc/network/interfaces.d/*
# The loopback network interface
auto lo
iface lo inet loopback
# The primary network interface
auto enp0s3
iface enp0s3 inet dhcp
正如你在上面输出中看到的,网卡启用了 DHCP。
现在,让我们来分配一个额外的地址,例如 192.168.1.104/24。
编辑 /etc/network/interfaces:
sudonano/etc/network/interfaces
如下添加额外的 IP 地址。
#Thisfile describes the network interfaces available on your system
#and how to activate them.Formore information, see interfaces(5).
source /etc/network/interfaces.d/*
# The loopback network interface
auto lo
iface lo inet loopback
# The primary network interface
auto enp0s3
iface enp0s3 inet dhcp
iface enp0s3 inet static
address 192.168.1.104/24
保存并关闭文件。
运行下面的命令使更改无需重启即生效。
sudo ifdown enp0s3 &&sudo ifup enp0s3
样例输出:
Killed old client process
InternetSystemsConsortium DHCP Client4.3.1
Copyright2004-2014InternetSystemsConsortium.
All rights reserved.
Forinfo, please visit https://www.isc.org/software/dhcp/
Listening on LPF/enp0s3/08:00:27:2a:03:4e
Sending on LPF/enp0s3/08:00:27:2a:03:4e
Sending on Socket/fallback
DHCPRELEASE on enp0s3 to 192.168.1.1 port 67(xid=0x225f35)
InternetSystemsConsortium DHCP Client4.3.1
Copyright2004-2014InternetSystemsConsortium.
All rights reserved.
Forinfo, please visit https://www.isc.org/software/dhcp/
Listening on LPF/enp0s3/08:00:27:2a:03:4e
Sending on LPF/enp0s3/08:00:27:2a:03:4e
Sending on Socket/fallback
DHCPDISCOVER on enp0s3 to 255.255.255.255 port 67 interval 3(xid=0xdfb94764)
DHCPREQUEST of 192.168.1.103 on enp0s3 to 255.255.255.255 port 67(xid=0x6447b9df)
DHCPOFFER of 192.168.1.103from192.168.1.1
DHCPACK of 192.168.1.103from192.168.1.1
bound to 192.168.1.103-- renewal in35146 seconds.
注意:如果你从远程连接到服务器,把上面的两个命令放到一行中非常重要,因为第一个命令会断掉你的连接。而采用这种方式可以保留你的 ssh 会话。
现在,让我们用下面的命令来检查一下是否添加了新的 IP:
sudoip address show enp0s3
输出样例:
2: enp0s3:<BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP groupdefault qlen 1000
link/ether 08:00:27:2a:03:4e brd ff:ff:ff:ff:ff:ff
inet 192.168.1.103/24 brd 192.168.1.255 scope global enp0s3
valid_lft forever preferred_lft forever
inet 192.168.1.104/24 brd 192.168.1.255 scope global secondary enp0s3
valid_lft forever preferred_lft forever
inet6 fe80::a00:27ff:fe2a:34e/64 scope link
valid_lft forever preferred_lft forever
很好!我们已经添加了额外的 IP。
再次 ping IP 地址进行验证。
sudoping192.168.1.104
样例输出:
PING 192.168.1.104(192.168.1.104)56(84) bytes of data.
64 bytes from192.168.1.104: icmp_seq=1 ttl=64time=0.137 ms
64 bytes from192.168.1.104: icmp_seq=2 ttl=64time=0.050 ms
64 bytes from192.168.1.104: icmp_seq=3 ttl=64time=0.054 ms
64 bytes from192.168.1.104: icmp_seq=4 ttl=64time=0.067 ms
好极了!它能正常工作。就是这样。
⑵ 请问各位大虾,我想在ubuntu中一个网卡配置两个IP地址,QQ1161913741
auto lo eth0
iface lo inet loopback
iface eth0 inet static
address 192.168.236.128
netmask 255.255.255.0
gateway 192.168.236.1
iface eth0:1 inet static
address 9.5.1.79
netmask 255.255.0.0
⑶ ubuntu怎么配置ip地址
1.修改配置文件blacklist.conf禁用IPV6:
sudo vi /etc/modprobe.d/blacklist.conf
2.在文档最后添加 blacklist ipv6,然后查看修改结果:
cat /etc/modprobe.d/blacklist.conf
3.设置IP(设置网卡eth0的IP地址和子网掩码)
sudo ifconfig eth0 192.168.2.1 netmask 255.255.255.0
4.设置网关
sudo route add default gw 192.168.2.254
5.设置DNS 修改/etc/resolv.conf,在其中加入nameserver DNS的地址1 和 nameserver DNS的地址2 完成。
6.重启网络服务(若不行,请重启ubuntu:sudo reboot):
sudo /etc/init.d/networking restart
7.查看当前IP:
ifconfig
⑷ ubuntu 中单个网卡设置多IP与MySQL问题
您好。肯定是您的系统中毒了,建议杀毒。无法启动服务可能是病毒限制了。
⑸ ubuntu系统网络配置可不可以实现多网卡多ip或者单网卡多ip同时访问外网,求详细解答,奖励不是问题
在不同网络配置环境下使用Ubuntu系统,建议通过不同的命令脚本来进行网络配置的切换。根据不同的网络情况,通过脚本修改网卡的IP地址,子网掩码,以及默认路由。
⑹ ubuntu18.04怎么配置ip地址
众所周知,ubuntu desktop配置静态IP地址是修改配置文件/etc/network/interfaces。然而,修改这个文件对ubuntu server没有效果。
ubuntu server 18.04静态IP地址配置方法如下:
vim /etc/netplan/50-cloud-init.yaml
yaml是一种通用配置文件格式,规定不能出现tab符号,修改时要注意这点。enp0s3是绑定静态IP的网卡,步骤如下:
1. dhcp4由true改为false
2. addresses填写你的静态IP地址(带掩码)
3. 增加gateway4,填写你的gateway。
4. nameservers等参数可参考下图,8.8.8.8,202.96.209.133是DNS服务器,填这两个就可以了。
5. 执行命令netplan apply立即生效。
一、查看各项信息,IP、网关、DNS
1. 查看IP:
ifconfig
2. 查看网关
netstat -rn 或 route -n
3. 查看DNS
cat /etc/resolv.conf
二、配置IP、网关、DNS
1. 使用ifupdown配置网络
1)如果要使用之前的方式配置网络,需要重新安装ifupdown:
sudo apt install ifupdown
2)修改配置文件/etc/network/interfaces:
配置文件修改如下:
iface ens160 inet static
2.address 210.72.92.25
3.gateway 210.72.92.254
4.netmask 255.255.255.0
5.dns-nameservers 8.8.8.8
3)重启网络服务使配置生效
sudo services network restrart
4)修改DNS
打开/etc/resolv.conf
sudo vim /etc/resolv.conf
重启服务生效:
sudo /etc/init.d/resolvconf restart #使DNS生效
2. 使用netplan配置网络(推荐)
1) 配置IP及网关
Ubuntu 18.04使用netplan配置网络,其配置文件是yaml格式的。安装好Ubuntu 18.04之后,在/etc/netplan/目录下默认的配置文件名是50-cloud-init.yaml,我们通过VIM修改它:
sudo vim /etc/netplan/50-cloud-init.yaml
配置文件修改如下:
network:
2.renderer: NetworkManager
3.ethernets:
4. enp0s31f6:
5. addresses:[210.72.92.28/24] # IP及掩码
6.gateway4: 210.72.92.254 # 网关
7.dhcp4: false
8.optional: true
9.nameservers:
10.addresses: [192.168.18.2, 114.114.114.114]
11.version: 2
这里把DNS和ipv4地址配置在一个文件里了,不用再修改/etc/resolv.conf 文件。
重启网络服务使配置生效
1.sudo netplan apply
2.ip addr list
⑺ 怎么把一个网卡设置多个IP地址
具体操作步骤如下:
1、以本地连接为例做介绍。 操作系统为WIN7。
打开本地连接配置界面
⑻ 如何给Ubuntu网站绑定多个IP,怎么给Ubuntu服务器设置多IP
多个不同IP段的 /etc/network/interfaces 配置文件的范例如下:
# The loopback network interface
auto lo
iface lo inet loopback
# The primary network interface
auto eth0
iface eth0 inet static
address 8.8.8.2
netmask 255.255.255.248
gateway 8.8.8.1 要注意这里,多个不同IP段,只要1个gateway配置即可,其他IP不需要配置gateway
auto eth0:0
iface eth0:0 inet static
address 8.8.8.3
netmask 255.255.255.248
auto eth0:1
iface eth0:1 inet static
address 8.8.8.4
netmask 255.255.255.248
auto eth0:2
iface eth0:2 inet static
address 8.8.8.5
netmask 255.255.255.248
auto eth0:3
iface eth0:3 inet static
address 8.8.8.6
netmask 255.255.255.248
auto eth0:4
iface eth0:4 inet static
address 6.6.6.130 注意这里,虽然这是不同的IP段,但是不需要配置gateway,只需要配置netmask即可
netmask 255.255.255.224
auto eth0:5
iface eth0:5 inet static
address 6.6.6.131
netmask 255.255.255.224
更多ip也类似配置即可。
配置文件完成后,用命令 /etc/init.d/networking restart 重启网络,不需要reboot重启服务器。 /etc/init.d/networking restart 重启网络的时候,如果你的配置文件有错误,那么他会提示你。比如IP重复了,书写错误了,等等。在执行此命令前,一定要小心检查interfaces配置文件,不然可能就把网络弄瘫痪,那时候就需要机房的工作人员去处理,十分麻烦。
/etc/init.d/networking restart错误分析案例:
[email protected]:/etc/network# /etc/init.d/networking restart
* Reconfiguring network interfaces...
/etc/network/interfaces:165: interface eth0:28 declared allow-auto twice
ifdown: couldn't read interfaces file "/etc/network/interfaces"
/etc/network/interfaces:165: interface eth0:28 declared allow-auto twice
ifup: couldn't read interfaces file "/etc/network/interfaces"
...fail!
说明eth0:28有重复,解决办法:vi interfaces找到eth0:28,删除掉重复的
[email protected]:/etc/network# /etc/init.d/networking restart
* Reconfiguring network interfaces...
/etc/network/interfaces:166: plicate interface
ifdown: couldn't read interfaces file "/etc/network/interfaces"
/etc/network/interfaces:166: plicate interface
ifup: couldn't read interfaces file "/etc/network/interfaces"
...fail!
说明166行有重复,解决办法:vi interfaces找到166行(set number),删除掉重复的
[email protected]:/etc/network# /etc/init.d/networking restart
* Reconfiguring network interfaces...
/etc/network/interfaces:162: plicate interface
ifdown: couldn't read interfaces file "/etc/network/interfaces"
/etc/network/interfaces:162: plicate interface
ifup: couldn't read interfaces file "/etc/network/interfaces"
说明162行有重复,解决办法:vi interfaces找到166行(set number),删除掉重复的
⑼ 一个网卡设置多个IP地址的方法是什么
1、在电脑的右下角联网的图标,右键选择“打开网络和interner设置”。
⑽ Ubuntu(Linux)下如何配置IP地址
一、使用命令设置ubuntu的ip地址
1.修改配置文件blacklist.conf禁用IPV6:
sudo vi /etc/modprobe.d/blacklist.conf
2.在文档最后添加 blacklist ipv6,然后查看修改结果:
cat /etc/modprobe.d/blacklist.conf
3.设置IP(设置网卡eth0的IP地址和子网掩码)
sudo ifconfig eth0 192.168.2.1 netmask 255.255.255.0
4.设置网关
sudo route add default gw 192.168.2.254
5.设置DNS 修改/etc/resolv.conf,在其中加入nameserver DNS的地址1 和 nameserver DNS的地址2 完成。
6.重启网络服务(若不行,请重启ubuntu:sudo reboot):
sudo /etc/init.d/networking restart
7.查看当前IP:
ifconfig
二、直接修改系统配置文件
ubuntu的网络配置文件是:/etc/network/interfaces
打开后里面可设置DHCP或手动设置静态ip。前面auto eth0,让网卡开机自动挂载。
1. 以DHCP方式配置网卡
编辑文件/etc/network/interfaces:
sudo vi /etc/network/interfaces
并用下面的行来替换有关eth0的行:
# The primary network interface - use DHCP to find our address
auto eth0
iface eth0 inet dhcp
用下面的命令使网络设置生效:
sudo /etc/init.d/networking restart
也可以在命令行下直接输入下面的命令来获取地址
sudo dhclient eth0
2. 为网卡配置静态IP地址
编辑文件/etc/network/interfaces:
sudo vi /etc/network/interfaces
并用下面的行来替换有关eth0的行:
# The primary network interface
auto eth0
iface eth0 inet static
address 192.168.2.1
gateway 192.168.2.254
netmask 255.255.255.0
#network 192.168.2.0
#broadcast 192.168.2.255
将上面的ip地址等信息换成你自己就可以了.用下面的命令使网络设置生效:
sudo /etc/init.d/networking restart
3. 设定第二个IP地址(虚拟IP地址)
编辑文件/etc/network/interfaces:
sudo vi /etc/network/interfaces
在该文件中添加如下的行:
auto eth0:1
iface eth0:1 inet static
address x.x.x.x
netmask x.x.x.x
network x.x.x.x
broadcast x.x.x.x
gateway x.x.x.x
根据你的情况填上所有诸如address,netmask,network,broadcast和gateways等信息:
用下面的命令使网络设置生效:
sudo /etc/init.d/networking restart
4. 设置主机名称(hostname)
使用下面的命令来查看当前主机的主机名称:
sudo /bin/hostname
使用下面的命令来设置当前主机的主机名称:
sudo /bin/hostname newname
系统启动时,它会从/etc/hostname来读取主机的名称。
5. 配置DNS
首先,你可以在/etc/hosts中加入一些主机名称和这些主机名称对应的IP地址,这是简单使用本机的静态查询。要访问DNS 服务器来进行查询,需要设置/etc/resolv.conf文件,假设DNS服务器的IP地址是192.168.2.2, 那么/etc/resolv.conf文件的内容应为:
search chotim.com
nameserver 192.168.2.2
6.手动重启网络服务:
sudo /etc/init.d/networking restart
返回结果如下:
*Reconfiguring network interfaces… [OK]