61阅读

ubuntu设置ip地址-Ubuntu系统下配置IP地址方法介绍

发布时间:2017-09-12 所属栏目:Ubuntu

一 : Ubuntu系统下配置IP地址方法介绍

接到一客户的服务器,开机已启动发现是Ubuntu系统,当时有点郁闷了,心想没有配置过ubuntu系统,这客户还在旁边了,心里有点紧张了,于是开始上网寻找各种方法配置,最终将IP配置好,给客户上架调试通了,算是歇了一口气;现在讲配置方式给大家分享一下;

配置IP方式有两种:

1、通过命令直接配置

sudo ifconfig eth0 IP地址 netmask 子网掩码------配置IP地

sudo route add default gw 网关------------添加默认路由

vi /etc/resolv.conf 配置文件 添加nameserver DNS----配置DNS

sudo /etc/init.d/networking restart-----------重启网卡配置
但是方式只能临时修改,当服务器重启后,配置信息丢失;第二种方式直接修改配置文件,重启服务器后配置信息不会丢失;

2、直接修改配置文件

Ubuntu 系统配置文件在:/etc/network/interfaces
编辑配置文件:sudo vi /etc/network/interfaces
并用下面的行来替换有关eth0的行:
# The primary network interface
auto eth0
iface eth0 inet static
address IP地址
gateway 网关
netmask 子网掩码
#network 192.168.2.0
#broadcast 192.168.2.255

根据你的情况填上所有诸如address,netmask,network,broadcast和gateways等信息:
sudo /etc/init.d/networking restart--重启网卡;使之配置生效

配置IP地址后,需要配置DNS;具体方式如下;

sudo vi //etc/resolv.conf 
search chotim.com
nameserver DNS服务器地址
sudo /etc/init.d/networking restart--重启网卡服务即可

二 : Ubuntu下ibus的设置

ubuntu下ibus的设置

ubuntu 装好后,默认的ibus输入法只能输入单个汉字,因此需要自己修改。[www.61k.com)首先在终端卸载ibus: sudo apt-get remove ibus 完成后运行安装 sudo apt-get install ibus sudo apt-get install ibus-pinyin 一般系统会提示: IBus 已经成功启动!如果你不能正常使用 IBus,请将下面代码加入到 $HOME/.bashrc中,并重新登录桌面。 export GTK_IM_MODULE=ibus export XMODIFIE

ubuntu 装好后,默认的ibus输入法只能输入单个汉字,因此需要自己修改。首先在终端卸载ibus:sudo apt-get remove ibus完成后运行安装sudo apt-get install ibus

sudo apt-get install ibus-pinyin

一般系统会提示:IBus 已经成功启动!如果你不能正常使用 IBus,请将下面代码加入到 $HOME/.bashrc中,并重新登录桌面。export GTK_IM_MODULE=ibus

export XMODIFIERS=@im=ibus

export QT_IM_MODULE=ibus

因此可以自己修改.bashrc文件。此文件原内容如下蓝色部分所示,红色部分为根据系统添加的内容。# ~/.bashrc: executed by bash(1) for non-login shells.

# see /usr/share/doc/bash/examples/startup-files (in the package bash-doc)# for examples

# If not running interactively, don't do anything

[ -z "$PS1" ] && return

# don't put duplicate lines in the history. See bash(1) for more options# don't overwrite GNU Midnight Commander's setting of `ignorespace'.HISTCONTROL=$HISTCONTROL${HISTCONTROL+,}ignoredups# ... or force ignoredups and ignorespace

HISTCONTROL=ignoreboth

# append to the history file, don't overwrite it

shopt -s histappend

# for setting history length see HISTSIZE and HISTFILESIZE in bash(1)# check the window size after each command and, if necessary,

# update the values of LINES and COLUMNS.

shopt -s checkwinsize

# make less more friendly for non-text input files, see lesspipe(1)

[ -x /usr/bin/lesspipe ] && eval "$(SHELL=/bin/sh lesspipe)"

# set variable identifying the chroot you work in (used in the prompt below)if [ -z "$debian_chroot" ] && [ -r /etc/debian_chroot ]; then

debian_chroot=$(cat /etc/debian_chroot)

fi

ibus Ubuntu下ibus的设置

# set a fancy prompt (non-color, unless we know we "want" color)

case "$TERM" in

xterm-color) color_prompt=yes;;

esac

# uncomment for a colored prompt, if the terminal has the capability; turned# off by default to not distract the user: the focus in a terminal window# should be on the output of commands, not on the prompt

#force_color_prompt=yes

if [ -n "$force_color_prompt" ]; then

if [ -x /usr/bin/tput ] && tput setaf 1 >&/dev/null; then

# We have color support; assume it's compliant with Ecma-48

# (ISO/IEC-6429). (Lack of such support is extremely rare, and such

# a case would tend to support setf rather than setaf.)

color_prompt=yes

else

color_prompt=

fi

fi

if [ "$color_prompt" = yes ]; then

PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\

[\033[01;34m\]\w\[\033[00m\]\$ '

else

PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '

fi

unset color_prompt force_color_prompt

# If this is an xterm set the title to user@host:dir

case "$TERM" in

xterm*|rxvt*)

PS1="\[\e]0;${debian_chroot:+($debian_chroot)}\u@\h: \w\a\]$PS1"

;;

*)

;;

esac

# enable color support of ls and also add handy aliases

if [ -x /usr/bin/dircolors ]; then

test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)"

alias ls='ls --color=auto'

#alias dir='dir --color=auto'

#alias vdir='vdir --color=auto'

alias grep='grep --color=auto'

alias fgrep='fgrep --color=auto'

alias egrep='egrep --color=auto'

fi

ibus Ubuntu下ibus的设置

# some more ls aliases

#alias ll='ls -l'

#alias la='ls -A'

#alias l='ls -CF'

# Alias definitions.

# You may want to put all your additions into a separate file like# ~/.bash_aliases, instead of adding them here directly.

# See /usr/share/doc/bash-doc/examples in the bash-doc package.if [ -f ~/.bash_aliases ]; then

. ~/.bash_aliases

fi

# enable programmable completion features (you don't need to enable# this, if it's already enabled in /etc/bash.bashrc and /etc/profile# sources /etc/bash.bashrc).

if [ -f /etc/bash_completion ] && ! shopt -oq posix; then

. /etc/bash_completion

fi

export GTK_IM_MODULE=ibus

export XMODIFIERS=@im=ibus

export QT_IM_MODULE=ibus

扩展:ubuntu ibus 设置 / ubuntu ibus / ubuntu ibus pinyin

三 : Ubuntu Server的一些简单安全设置简介

一、用户概述
 
默认状况下,ubuntu server的root用户是不启用的,一般用户通过在命令前加前缀”sudo”,来暂时获得管理员权限。随后会提示输入password,此password与一般用户的密码一样。也可以通过 sudo –i来将一般用户提升为超级用户。
 
启用root帐号仅需运行sudo passwd root,然后根据提示输入密码即可激活root.如果要关闭root用户,仅需运行 sudo passwd –l root即可。
 
Root帐号的密码和普通用户使用sudo的密码没有任何联系。root帐号和普通帐号的sudo不同之处在于,使用root帐号登陆后权限始终为管理员权限,而普通帐号的sudo,仅在执行某一命令时是管理员权限,当执行完命令后又会自动降为普通用户权限。
 
二、用户密码的设置与恢复
 
使用命令 sudo passwd user-name,然后根据提示输入sudo密码,如果验证通过,则会提示为user-name输入新密码。此命令同样可以为root设置和恢复密码。
 
三、GRUB的安全性
 
GRUB用于引导系统及进行系统恢复。可以通过对其进行添加操作密码的方式,来增加其安全性。主要是对”/boot/grub/menu.lst”进行修改。示例如下:
 
没有修改前:
 



default 0 </p> <p>timeout 10 </p> <p>title Ubuntu,kernel 2.6.15-26-server-LAMP </p> <p>root (hd0,2) </p> <p>kernel /boot/vmlinuz-2.6.15-server root=/dev/hda3 ro quiet splash </p> <p>initrd /boot/initrd.img-2.6.15-server </p> <p>savedefault </p> <p>boot


修改后:
 
 


default 0 </p> <p>timeout 10 </p> <p>password=12345 </p> <p>title Ubuntu,kernel 2.6.15-26-server-LAMP </p> <p>lock </p> <p>root (hd0,2) </p> <p>kernel /boot/vmlinuz-2.6.15-server root=/dev/hda3 ro quiet splash </p> <p>initrd /boot/initrd.img-2.6.15-server </p> <p>savedefault </p> <p>boot


然后reboot系统,待出现GRUB画面时,将光标移到该选项处,按下‘p’,输入密码12345即可。通过这种方式,可以有效地防止通过recovery mode进行恶意破坏,如修改root密码等。
 
由于以上方式的密码是以明文的形式出现在menu.lst中,也具有危险性,因此可采取对其加密的方式。具体如下:
 
sudo grub-md5-crytp ,然后根据提示输入两遍 12345(请更改为任意字符),之后出现31个字符,记录下该字符串。将password=12345 修改为password --md5 31位字符串,reboot系统即可。
 
四、使用救援光碟恢复系统
 
当忘掉GRUB密码或因某种原因GRUB无法启动,此时即可使用救援光碟。将光碟放入CDROM,reboot系统,待出现启动条目时,移动光标至”Resuce broken system”.随后会自动监测系统硬件,如语言种类、网路接口、硬盘等。最后将出现命令行选项:
 
 


Execute a Shell in /dev/discs/disc0/part1 </p> <p>Execute a Shell in the installer environment </p> <p>Reinstall GRUB boot loader </p> <p>Choose a different root file system </p> <p>Reboot the system


选择第一项,随后进入bash shell。
 
注意:/dev/discs/disc0/part1 中的part1表示欲恢复的系统安装的分区,应根据实际情况选择。
 
 
五、Summary
 
处于安全考虑:
 
1 root帐户应该disable;
 
2 GRUB应设置MD5密码;
 
3 应设置BIOS,使禁止从CD-ROM启动系统。

六、确保SSH的安全性


SSH对于远程管理一台服务器来说是一个好方法。然而,SSH仍然存在着诸多问题。服务器和客户端的通信是安全的,不过这并不意味着涉及到的主机也是安全的。向外部世界打开一个SSH服务也就意味着允许强力攻击。
我们可以采取一些极为简单的方法来真正地强化经由SSH的远程访问,特别是我们不能将这种服务与源端口的一个有限数量相联系时。
先说一件重要的事情,sshd_config。在Ubuntu中,这通常在/etc/ssh中可以找到,它可以用于配置大量的特性。最简单的往往是最好的。限制可以通过SSH登录的用户是一个首要的原则。这可以用如下两种方法完成:根据用户或者根据组。AllowGroups允许一个组的任何经鉴定的用户通过SSH访问服务器。不过,一个更加精细的方法是使用AllowUsers选项。
另一个简单的方法是将监听端口从22号端口移到某个其它的随机指定的端口。这就减少了显示SSHD运行状态扫描的可能性。
我们还可以禁用对根的访问,并禁用口令验证而只使用密钥验证。
下一步就是使用一个称为Denyhosts的小工具,大家可以从http://denyhosts.sourceforge.net/下载它。我们一定要保证启用/etc/apt/source.list中的资源,然后键入下面的命令:


sudo apt-get update
sudo apt-get install denyhosts


DenyHosts意在由Linux系统管理员运行,以帮助其挫败对SSH服务器的攻击(也称为基于字典的攻击或强力攻击)的企图。
DenyHosts充当着一个对SSH和其它服务的动态阻击器,它依靠/etc/hosts.deny和 hosts.allow进行工作,并能够以动态方式构建重复地与我们的服务器连接的主机列表。默认情况下,这项服务会阻止来自那些不断地试图与我们的主机连接并实施访问的IP地址源。Denyhosts的处理在/etc/denyhosts.conf中进行配置。
我们还可以通过Iptables行连接速率的限制,而且我们还应该在服务器上部署防火墙。
一旦这些布置停当,我们就会确信自己在一台面向公众的主机上拥有了一个更加安全的SSH。

本文标题:ubuntu设置ip地址-Ubuntu系统下配置IP地址方法介绍
本文地址: http://www.61k.com/1078936.html

61阅读| 精彩专题| 最新文章| 热门文章| 苏ICP备13036349号-1