如何在 Linux 中从命令行更改 IP 地址如何在 Linux 中从命令行更改 IP 地址如何在 Linux 中从命令行更改 IP 地址如何在 Linux 中从命令行更改 IP 地址
  • 文章
  • 正则表达式
    • 工具
  • 登录
找到的结果: {phrase} (显示: {results_count} 共: {results_count_total})
显示: {results_count} 共: {results_count_total}

加载更多搜索结果...

搜索范围
模糊匹配
搜索标题
搜索内容
发表 admin at 2025年2月28日
类别
  • 未分类
标签

如何在 Linux 中从命令行更改 IP 地址

这个技巧应该适用于所有基于 Debian 的 Linux 发行版,包括 Ubuntu。要开始,请在终端提示符下键入 ifconfig,然后按 Enter。此命令列出系统上的所有网络接口,因此请记下要更改 IP 地址的接口的名称。

要更改设置,您还可以使用 ifconfig 命令,这次带有一些附加参数。以下命令将名为“eth0”的网络接口更改为使用 IP 地址 102.168.0.1,并分配子网掩码 255.255.255.0:

sudo ifconfig eth0 192.168.0.1 netmask 255.255.255.0

当然,您可以替换为您想要的任何值。如果您再次运行 ifconfig,您将看到您的接口现在已经采用了您分配给它的新设置。

如果还需要更改网络接口使用的默认网关,可以使用 route 命令。例如,以下命令将“eth0”接口的默认网关设置为 192.168.0.253:

sudo route add default gw 192.168.0.253 eth0

要查看新设置,您需要显示路由表。在提示符下键入以下命令,然后按 Enter:

route -n

这就是从终端更改您的 IP 地址的全部内容。如果您对可以在终端上使用的其他出色网络工具感兴趣,请务必查看我们的主题指南。

Linux Commands
Files tar · pv · cat · tac · chmod · grep · diff · sed · ar · man · pushd · popd · fsck · testdisk · seq · fd · pandoc · cd · $PATH · awk · join · jq · fold · uniq · journalctl · tail · stat · ls · fstab · echo · less · chgrp · chown · rev · look · strings · type · rename · zip · unzip · mount · umount · install · fdisk · mkfs · rm · rmdir · rsync · df · gpg · vi · nano · mkdir · du · ln · patch · convert · rclone · shred · srm · scp · gzip · chattr · cut · find · umask · wc
Processes alias · screen · top · nice · renice · progress · strace · systemd · tmux · chsh · history · at · batch · free · which · dmesg · chfn · usermod · ps · chroot · xargs · tty · pinky · lsof · vmstat · timeout · wall · yes · kill · sleep · sudo · su · time · groupadd · usermod · groups · lshw · shutdown · reboot · halt · poweroff · passwd · lscpu · crontab · date · bg · fg · pidof · nohup · pmap
Networking netstat · ping · traceroute · ip · ss · whois · fail2ban · bmon · dig · finger · nmap · ftp · curl · wget · who · whoami · w · iptables · ssh-keygen · ufw · arping · firewalld

RELATED: Best Linux Laptops for Developers and Enthusiasts

©2015-2025 艾丽卡 support@alaica.com