刚装的新系统需要调整一些配置才能更好的工作,下面纪录一些常见的配置
1. 设置 允许root用户ssh远程登录
sudo vi /etc/ssh/sshd_config
调整PermitRootLogin
参数值为yes
重启sshd服务生效
systemctl restart sshd.service
2. 设置软件源
打开文件
vi /etc/apt/sources.list
初始内容如下
#
# deb cdrom:[Debian GNU/Linux 9.8.0 _Stretch_ - Official amd64 DVD Binary-1 20190216-11:59]/ stretch contrib main
deb cdrom:[Debian GNU/Linux 9.8.0 _Stretch_ - Official amd64 DVD Binary-1 20190216-11:59]/ stretch contrib main
deb http://mirrors.163.com/debian/ stretch main
deb-src http://mirrors.163.com/debian/ stretch main
deb http://security.debian.org/debian-security stretch/updates main contrib
deb-src http://security.debian.org/debian-security stretch/updates main contrib
# stretch-updates, previously known as 'volatile'
deb http://mirrors.163.com/debian/ stretch-updates main contrib
deb-src http://mirrors.163.com/debian/ stretch-updates main contrib
先将deb cdrom:
开头的一行去掉,保存
运行update
apt update
也可以添加其他软件源,自行百度
3. 安装必要的软件
3.1 安装vim
apt install vim
4. 修改网卡名称为eth开头
vim /etc/default/grub
在GRUB_CMDLINE_LINUX
后面加入net.ifnames=0 biosdevname=0
部分内容如下:
root@debian:~# cat /etc/default/grub
# If you change this file, run 'update-grub' afterwards to update
# /boot/grub/grub.cfg.
# For full documentation of the options in this file, see:
# info -f grub -n 'Simple configuration'
GRUB_DEFAULT=0
GRUB_TIMEOUT=5
GRUB_DISTRIBUTOR=`lsb_release -i -s 2> /dev/null || echo Debian`
GRUB_CMDLINE_LINUX_DEFAULT="quiet"
GRUB_CMDLINE_LINUX="net.ifnames=0 biosdevname=0"
运行下面命令将修改的内容写入boot grub.cfg文件
update-grub
或者
grub-mkconfig -o /boot/grub/grub.cfg
上面修改了网卡名称,那么配置ip的地方也要修改
vim /etc/network/interfaces
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).
source /etc/network/interfaces.d/*
# The loopback network interface
auto lo
iface lo inet loopback
# The primary network interface
allow-hotplug ens33
iface ens33 inet dhcp
将ens33修改为eth0保存
重启系统后,再看到的网卡名称就是eth开头的了
5. 修改为静态ip
最好为每个网卡设置一个独立的配置文件
先将/etc/network/interfaces
文件中关于eth0的配置注销掉
如添加一个eth0的配置文件
vim /etc/network/interfaces.d/eth0.cfg
内容如下
auto eth0
iface eth0 inet static
address 192.168.144.200
netmask 255.255.255.0
gateway 192.168.144.2
重启生效
注意:
如果使用
systemctl restart networking.service
或者
/etc/init.d/networking restart
可能会出现双ip的情况
root@debian:~# ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether 00:0c:29:8e:a9:f6 brd ff:ff:ff:ff:ff:ff
inet 192.168.144.131/24 brd 192.168.144.255 scope global eth0
valid_lft forever preferred_lft forever
inet 192.168.144.200/24 brd 192.168.144.255 scope global secondary eth0
valid_lft forever preferred_lft forever
inet6 fe80::20c:29ff:fe8e:a9f6/64 scope link
valid_lft forever preferred_lft forever
root@debian:~#
上面有旧的ip 131和新的静态ip 200
6. 设置域名服务器
vim /etc/resolv.conf
如添加行
nameserver 8.8.8.8
保存退出即生效
7. 为ls和grep加入颜色
默认~/.bashrc
文件内容
root@debian:~# cat .bashrc
# ~/.bashrc: executed by bash(1) for non-login shells.
# Note: PS1 and umask are already set in /etc/profile. You should not
# need this unless you want different defaults for root.
# PS1='${debian_chroot:+($debian_chroot)}\h:\w\$ '
# umask 022
# You may uncomment the following lines if you want `ls' to be colorized:
# export LS_OPTIONS='--color=auto'
# eval "`dircolors`"
# alias ls='ls $LS_OPTIONS'
# alias ll='ls $LS_OPTIONS -l'
# alias l='ls $LS_OPTIONS -lA'
#
# Some more alias to avoid making mistakes:
# alias rm='rm -i'
# alias cp='cp -i'
# alias mv='mv -i'
root@debian:~#
修改为如下
root@debian:~# cat ~/.bashrc
# ~/.bashrc: executed by bash(1) for non-login shells.
# Note: PS1 and umask are already set in /etc/profile. You should not
# need this unless you want different defaults for root.
# PS1='${debian_chroot:+($debian_chroot)}\h:\w\$ '
# umask 022
# You may uncomment the following lines if you want `ls' to be colorized:
export LS_OPTIONS='--color=auto'
eval "`dircolors`"
alias ls='ls $LS_OPTIONS'
alias ll='ls $LS_OPTIONS -l'
alias l='ls $LS_OPTIONS -lA'
#
# Some more alias to avoid making mistakes:
# alias rm='rm -i'
# alias cp='cp -i'
# alias mv='mv -i'
alias grep='grep --color=auto'
root@debian:~#
立即生效,运行
. ~/.bashrc
或者退出终端,重新登录,也会生效