Ubuntu server配置IP地址

15 篇文章 0 订阅
11 篇文章 0 订阅

转自:http://www.yimiju.com/articles/411.html

因为Ubuntu Server不像桌面版Ubuntu那样,可以非常简单的通过图形操作界面配置网卡IP。

所以Yimiju再此讲解下手动修改网卡IP的两种方法:

第一种方法:常规方法

1、登录Ubuntu Server,然后通过“sudo -s” 切换到root用户。

2、输入“cd /etc/network/”,回车,到network目录。

3、输入“ls”,回车,看看是否存在interfaces文件。

4、输入“vim interfaces”,回车,进去编辑界面。

5、按键盘上的“Insert”键,然后移动光标至你要修改的地方进行修改。

6、然后按“Esc”退出编辑,在按“Shift+:”输入“wq”,回车,保存并退出。

7、输入“reboot”重启,重启ubuntu之后你再用ifconfig看看,IP应该修改好了。

第二种:“临时性修改”

这里的“临时性修改”指的是你只需要临时性的给你的Ubuntu Server更换个内网IP,

方法很简单:

1、登录Ubuntu Server,然后通过“sudo -s”切换到root用户。

2、输入“ifconfig eth0 xxx.xxx.xxx.xxx”,回车。

eth指的是你的物理网卡,如果你的网卡号是eth1,那上面的命令也要做相应的修改。

xxx.xxx.xxx.xxx指的是你要指派的IP地址,例如:192.168.1.123.

注意:这种方法简单快速,但是只是临时修改了内网IP地址,重启ubuntu之后又会变回修改前的IP。

具体修改IP的方法:

Edit

$sudo vi /etc/network/interfaces
and adjust it to your needs (in this example setup I will use the IP address 192.168.0.100):

# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).

# The loopback network interface
auto lo
iface lo inet loopback

# This is a list of hotpluggable network interfaces.
# They will be activated automatically by the hotplug subsystem.
mapping hotplug
        script grep
        map eth0

# The primary network interface
auto eth0
iface eth0 inet static
        address 192.168.0.100      # This is your IP
        netmask 255.255.255.0
        network 192.168.0.0
        broadcast 192.168.0.255
        gateway 192.168.0.1

Then do

sudo /etc/init.d/networking restart

to restart the network.
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Ubuntu配置网络的 IP 地址有几种方式,下面我将介绍两种常用的方法: 方法一:使用 netplan 进行配置 1. 打开终端,运行以下命令编辑 netplan 配置文件: ``` sudo nano /etc/netplan/00-installer-config.yaml ``` 2. 在文件中,找到 `eth0`(或其他网络接口名字),在下面添加以下内容: ``` addresses: [your_ip_address/subnet_mask] gateway4: your_default_gateway nameservers: addresses: [your_dns_server_1, your_dns_server_2] ``` 请将 `your_ip_address` 替换为你想要分配的 IP 地址,`subnet_mask` 替换为子网掩码,`your_default_gateway` 替换为默认网关的 IP 地址,`your_dns_server_1` 和 `your_dns_server_2` 替换为 DNS 服务器的 IP 地址。 3. 保存并退出文件。 4. 运行以下命令应用配置更改: ``` sudo netplan apply ``` 方法二:使用 ifconfig 进行临时配置 1. 打开终端,运行以下命令查看当前网络接口名字: ``` ifconfig ``` 2. 运行以下命令配置 IP 地址: ``` sudo ifconfig [interface_name] [your_ip_address] netmask [subnet_mask] ``` 请将 `[interface_name]` 替换为你想要配置的网络接口名字,`[your_ip_address]` 替换为你想要分配的 IP 地址,`[subnet_mask]` 替换为子网掩码。 3. 运行以下命令设置默认网关: ``` sudo route add default gw [your_default_gateway] ``` 请将 `[your_default_gateway]` 替换为默认网关的 IP 地址。 4. 运行以下命令设置 DNS 服务器: ``` sudo echo "nameserver [your_dns_server_1]" >> /etc/resolv.conf sudo echo "nameserver [your_dns_server_2]" >> /etc/resolv.conf ``` 请将 `[your_dns_server_1]` 和 `[your_dns_server_2]` 替换为 DNS 服务器的 IP 地址。 请记得在以上方法中,将方括号内的内容替换为你实际的网络配置信息。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值