Ubuntu 12.04 LTS命令行设置IP及DNS设置方法点此进入

Ubuntu 版本命令行设置IP

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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
dns-search .COM

重启网卡: /etc/init.d/networking restatr

redhat Linux版本命令行设置IP

1
ifconfig eth0 新ip

然后编辑/etc/sysconfig/network-scripts/ifcfg-eth0,修改ip

修改IP地址

1
2
3
4
5
6
7
[aeolus@db network-scripts]$ vi ifcfg-eth0
DEVICE=eth0
ONBOOT=yes
BOOTPROTO=static
IPADDR=219.136.241.211
NETMASK=255.255.255.128
GATEWAY=219.136.241.254

修改网关

1
2
3
4
vi /etc/sysconfig/network
NETWORKING=yes
HOSTNAME=Aaron
GATEWAY=192.168.1.1

修改DNS

1
2
3
[aeolus@db etc]$ vi resolv.conf
nameserver 202.96.128.68
nameserver 219.136.241.206

重新启动网络配置

1
/etc/init.d/network restart

例子

修改ip地址

  • 即时生效:# ifconfig eth0 192.168.0.20 netmask 255.255.255.0
  • 启动生效:修改/etc/sysconfig/network-scripts/ifcfg-eth0

修改”default gateway”

  • 即时生效:# route add default gw 192.168.0.254
  • 启动生效,修改:/etc/sysconfig/network-scripts/ifcfg-eth0
  • 修改dns:/etc/resolv.conf,修改后可即时生效,启动同样有效

修改host name

  • 即时生效:# hostname fc2

启动生效,修改:/etc/sysconfig/network

1
2
3
4
5
6
7
8
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

添加Linux系统启动项

1
vi /etc/rc.d/rc.local

修改Linux系统SSH的端口号 操作系统Linux和Unix都适用:

修改配置文件 /etc/ssh/sshd_config,将里面的Port改为新端口(此端口必须是没有程序用到),比如10022

然后 kill -HUP 'cat /var/run/sshd.pid' 就行了。

注:现有连接自己不会断,因为kill -HUP cat /var/run/sshd.pid 只是HUP监听的那个,已经建立的连接(不同的 pid)不会断。

要想重新启用并用新端口登陆 ,此时可以在本登陆帐户下 用 exit 命令退出,在用新的端口登陆即可!