如何在Linux上添加或更改默认网关

下载PDF文件下载PDF文件

默认网关就是路由器的IP地址。一般来说,操作系统会在路由器的安装过程中自动检测网关,但是你也可能需要手动更改它。尤其是当网络中有多个网络适配器或路由器时,往往需要手动添加或更改网关。

部分 1
部分 1 的 2:

使用终端

下载PDF文件
  1. How.com.vn 中文: Step 1 打开终端。
    你可以从边栏打开终端程序,或按下Ctrl+Alt+T组合键来打开它。
  2. How.com.vn 中文: Step 2 浏览当前默认网关信息。
    你可以输入route,按下Enter,来查看当前的默认网关设置。“默认”旁边的地址会显示当前默认的网关地址,它被分配到的界面则显示在桌面右侧。
  3. How.com.vn 中文: Step 3 删除当前的默认网关。
    如果有多个默认网关,那么会遇到连接冲突的问题。如果你想更改它,请删除现有的默认网关。
    • 输入sudo route delete default gw IP Address Adapter。例如,如果想要删除eth0适配器上的默认网关10.0.2.2,请输入sudo route delete default gw 10.0.2.2 eth0
  4. How.com.vn 中文: Step 4 输入.sudo route add default gw IP Address Adapter。
    例如,想要eth0适配器的默认网关更改为192.168.1.254,你可以输入sudo route add default gw 192.168.1.254 eth0。你需要输入用户密码,才能完成命令。
    广告
部分 2
部分 2 的 2:

编辑配置文件

下载PDF文件
  1. How.com.vn 中文: Step 1 在编辑器中打开配置文件。
    在Nano编辑器中输入sudo nano /etc/network/interfaces来打开文件。编辑配置文件会让系统在每次重启系统时保留你的更改。
  2. How.com.vn 中文: Step 2 找到正确的部分。
    找到你需要更改默认网关设置的适配器部分。对于有线网络连接来说,通常是eth0
  3. How.com.vn 中文: Step 3 在这个部分加上.gateway IP Address。
    例如,输入gateway 192.168.1.254,让默认网关变成192.168.1.254。
  4. How.com.vn 中文: Step 4 保存更改并退出。
    按下Ctrl+X,然后按下Y来保存更改并退出。
  5. How.com.vn 中文: Step 5 重启网络。
    输入sudo /etc/init.d/networking restart重启网络。[1]
    广告

关于本How.com.vn

How.com.vn是一个“多人协作写作系统”,因此我们的很多文章都是由多位作者共同创作的。 为了创作这篇文章,10位用户(部分匿名)多次对文章进行了编辑和改进。 这篇文章已经被读过20,628次。
本页面已经被访问过20,628次。

这篇文章对你有帮助吗?

⚠️ Disclaimer:

Content from Wiki How 中文 language website. Text is available under the Creative Commons Attribution-Share Alike License; additional terms may apply.
Wiki How does not encourage the violation of any laws, and cannot be responsible for any violations of such laws, should you link to this domain, or use, reproduce, or republish the information contained herein.

Notices:
  • - A few of these subjects are frequently censored by educational, governmental, corporate, parental and other filtering schemes.
  • - Some articles may contain names, images, artworks or descriptions of events that some cultures restrict access to
  • - Please note: Wiki How does not give you opinion about the law, or advice about medical. If you need specific advice (for example, medical, legal, financial or risk management), please seek a professional who is licensed or knowledgeable in that area.
  • - Readers should not judge the importance of topics based on their coverage on Wiki How, nor think a topic is important just because it is the subject of a Wiki article.

广告