最新消息:

Debian常用操作

IT技术 ipcpu 4388浏览

Debian常用操作

For CentOS/RedHat users.

1. 修改主机名hostname

主机名写入/etc/hostname

执行脚本:

  1. $sudo /etc/init.d/hostname.sh start

在/etc/hosts中添加主机名对应的IP地址。

2. sudoers文件不存在

  1. $sudo apt-get install sudo

安装完即可生成/etc/sudoers

3. apt源修改

编辑文件/etc/apt/sources.list修改

  1. deb http://mirror.bit.edu.cn/debian wheezy main non-free contrib
  2. deb http://mirror.bit.edu.cn/debian wheezy-proposed-updates main contrib non-free
  3. deb-src http://mirror.bit.edu.cn/debian wheezy main non-free contrib
  4. deb-src http://mirror.bit.edu.cn/debian wheezy-proposed-updates main contrib non-free
  5. deb http://mirror.bit.edu.cn/debian-security wheezy/updates main contrib non-free
  6. deb-src http://mirror.bit.edu.cn/debian-security wheezy/updates main contrib non-free

然后执行apt-get update更新一下。

4. apt-get的使用

  1. ##查询软件库中的软件
  2. apt-cache search libcurl
  3. ##安装软件
  4. apt-get install libcurl3 libcurl3-gnutls
  5. ##查询已经安装的软件
  6. dpkg -l |grep php5 [类似于rpm -qa]
  7. ##删除已安装的软件包
  8. apt-get remove nginx

5. alias添加ll命令

修改/etc/profile,重新加载source /etc/profile即可。

  1. # last line: add aliases
  2. alias ll='ls $LS_OPTIONS -l'
  3. alias l='ls $LS_OPTIONS -lA'
  4. alias rm='rm -i'
  5. alias cp='cp -i'
  6. alias mv='mv -i'

6. ll 列目录无颜色区分

打开/root/.bashrc文件
去掉相应的注释即可。

  1. export LS_OPTIONS='--color=auto'
  2. eval "`dircolors`"

7. 时区修改

7.1 查看当前时区和时间

  1. drasaonline-8-game-01:/bin# date -R
  2. Fri, 07 Nov 2013 22:26:01 +0800

7.2 弹出shell菜单选择

  1. dpkg-reconfigure tzdata

7.3 手动设置

  1. echo "Asia/Shanghai" > /etc/timezone
  2. cp /usr/share/zoneinfo/PRC /etc/localtime

注: debian 下面的 crontab 是不会根据 /etc/localtime ,而是要读取 /etc/timezone 中的时区设置。

8. 网卡及路由配置

8.1. 网卡配置文件

  1. drasaonline-8-game-01:/bin# cat /etc/network/interfaces
  2. # The loopback network interface
  3. auto lo
  4. iface lo inet loopback
  5. #eth0 config
  6. auto eth0
  7. iface eth0 inet static
  8. address 10.127.129.178
  9. netmask 255.255.255.0
  10. network 10.127.129.0
  11. broadcast 10.127.129.255
  12. gateway 10.127.129.84
  13. #route
  14. up route add -net 10.0.0.0 netmask 255.0.0.0 gw 10.127.129.254
  15. down route del -net 10.0.0 netmask 255.0.0.0 gw 10.127.129.254
  16. #eth1 config
  17. auto eth1
  18. iface eth1 inet static
  19. address 121.1.1.1
  20. netmask 255.255.255.0
  21. network 121.1.1.0
  22. broadcast 121.1.1.255

8.2. 重启网络

  1. /etc/init.d/networking restart

8.3. 一个网卡配多个IP

  1. auto eth0:0
  2. allow-hotplug eth0:0
  3. iface eth0:0 inet static
  4. address 192.168.1.43
  5. netmask 255.255.255.0

8.4. 网卡配置文件中auto和allow-hotplug的区别
http://openwares.net/linux/interfaces_auto_allow-hotplug.html

9. 编译工具安装

  1. apt-get install build-essential

10. 系统服务的设定

10.1 chkconfig
如果觉着RedHat里面的chkconfig好用可以安装一个直接用,方法和RH一致。

  1. apt-get install chkconfig

10.2 修改现有系统服务运行状态
安装sysv-rc-conf可以对现有系统服务的状态进行查看和修改,但不能增加删除。

  1. apt-get install sysv-rc-conf
  2. sysv-rc-conf --list
  3. sysv-rc-conf --level 234 apache2 off

10.3 增加和删除系统服务

  1. insserv myserver #添加服务
  2. insserv -r myserver #删除服务

另还有一个命令update-rc.d可以使用。

11. 防火墙设定

11.1. 确保已经安装了iptables防火墙
11.2. 使用iptables -A添加相应的防火墙规则
11.3. 保存防火墙规则

  1. iptables-save > /etc/firewall.conf

11.4. 设置启动时加载防火墙规则

  1. echo "#!/bin/sh" > /etc/network/if-up.d/iptables
  2. echo "iptables-restore < /etc/firewall.conf" >> /etc/network/if-up.d/iptables
  3. chmod +x /etc/network/if-up.d/iptables

12. 其他事项

Debian的默认shell是dash,需注意识别。
默认vi 无法使用退格键backspace,可以按照vim替代。

来自为知笔记(Wiz)

转载请注明:IPCPU-网络之路 » Debian常用操作