linux下修改IP、DNS、路由命令行设置 ubuntu 版本命令行设置IP.
cat /etc/network/interfaces
# 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
# The primary network interface
auto eth0
iface eth0 inet static
address 192.168.1.104
netmask 255.255.255.0
network 192.168.1.0
broadcast 192.168.1.255
gateway 192.168.1.2
# dns-* options are implemented by the resolvconf package, if installed
dns-nameservers 58.22.96.66 218.104.128.106 202.101.138.8
重启网卡:
/etc/init.d/networking restatr
redhat linux版本命令行设置IP:
ifconfig eth0 新ip
然后编辑 /etc/sysconfig/network-scripts/ifcfg-eth0
,修改ip.
一、修改IP地址
vi ifcfg-eth0
DEVICE=eth0
ONBOOT=yes
BOOTPROTO=static
IPADDR=219.136.241.211
NETMASK=255.255.255.128
GATEWAY=219.136.241.254
二、修改网关
vi /etc/sysconfig/network
NETWORKING=yes
HOSTNAME=Aaron
GATEWAY=192.168.1.1
三、修改DNS
vi resolv.conf
nameserver 202.96.128.68
nameserver 219.136.241.206
四、重新启动网络配置
/etc/init.d/network restart
五、例子
1、修改ip地址 即时生效:
ifconfig eth0 192.168.0.20 netmask 255.255.255.0
启动生效:
vi /etc/sysconfig/network-scripts/ifcfg-eth0
2、修改default gateway 即时生效:
route add default gw 192.168.0.254
启动生效:
vi /etc/sysconfig/network-scripts/ifcfg-eth0
修改dns:
vi /etc/resolv.conf
修改后可即时生效,启动同样有效.
3、修改hostname 即时生效:
hostname fc2
启动生效:
vi /etc/sysconfig/network
ps:
DEVICE=eth0
BOOTPROTO=static
IPADDR=192.168.8.85
NETMASK=255.255.248.0
GATEWAY=192.168.8.1
HWADDR=00:0uu3:47:2C:D5:40
ONBOOT=yes
4、添加linux系统启动项
vi /etc/rc.d/rc.local
5、修改Linux系统SSH的端口号 修改Linux系统SSH的端口号 操作系统linux和Unix都适用: 修改配置文件 /etc/ssh/sshd_config
,将里面的Port改为新端口(此端口必须是没有程序用到),比如10022, 然后:
kill -HUP cat /var/run/sshd.pid
就行了.