How to Change the Hostname of a Linux System

How to Change the Hostname of a Linux System

refer from : http://www.ducea.com/2006/08/07/how-to-change-the-hostname-of-a-linux-system/

Normally we will set the hostname of a system during the installation process. Many peoples don’t care about this, and don’t change the hostname even if for example this was set to something really stupid by the datacenter that installed the system (most likely they will set this to “debian” on any debian installation, etc). For me, it is important to see on each one of the ssh screens I will have open at any time a different hostname that is relevant and will give me quickly the information on what system I am logged in.

Change the hostname on a running system

On any Linux system you can change its hostname with the command ’hostname’ (surprised?)… Here are some quick usages of the command line hostname:

hostname

without any parameter it will output the current hostname of the system.

hostname –fqd

it will output the fully qualified domain name (or FQDN) of the system.

hostname NEW_NAME

will set the hostname of the system to NEW_NAME. This is active right away and will remain like that until the system will be rebooted (because at system boot it will set this from some particular file configurations – see bellow how to set this permanently). You will most probably need to exit the current shell in order to see the change in your shell prompt.

Permanent hostname change on Debian based systems

Debian based systems use the file /etc/hostname to read the hostname of the system at boot time and set it up using the init script /etc/init.d/hostname.sh

/etc/hostname

server

So on a Debian based system we can edit the file /etc/hostname and change the name of the system and then run:

/etc/init.d/hostname.sh start

to make the change active. The hostname saved in this file (/etc/hostname) will be preserved on system reboot (and will be set using the same script we used hostname.sh).

Permanent hostname change on RedHat based systems

RedHat based system use the file /etc/sysconfig/network to read the saved hostname at system boot. This is set using the init script /etc/rc.d/rc.sysinit

/etc/sysconfig/network

NETWORKING=yes

HOSTNAME=”plain.domainname.com”

GATEWAY=”192.168.0.1″

GATEWAYDEV=”eth0″

FORWARD_IPV4=”yes”

So in order to preserve your change on system reboot edit this file and enter the appropriate name using the HOSTNAME variable.

Use sysctl to change the hostname

Why would someone need a different method of doing the same thing as above? No idea, but here is anyway: use sysctl to change the variable kernel.hostname: Use:

sysctl kernel.hostname

to read the current hostname, and

sysctl kernel.hostname=NEW_HOSTNAME

to change it.

 

No manual entry for printf in section 3

No manual entry for printf in section 3

Fedora && Ubuntu 安装manual

clip_image001

Fedora

用虚拟机装好fedora 19之后,竟然查阅不到,

直接yum install man-pages即可解决。

Ubuntu

网上看到说是安装manpages-dev即可。

亮点

clip_image002

现在fedora19grouplist多了好几个比较好的包,比如:

GNOME Desktop

   KDE Plasma Workspaces

   Xfce Desktop

   LXDE Desktop

   Cinnamon Desktop

   MATE Desktop

   Sugar Desktop Environment

   Development and Creative Workstation

   Web Server

   Infrastructure Server

   Basic Desktop

   Minimal Install

   C Development Tools and Libraries

   Development Tools

   LibreOffice

   RPM Development Tools

   System Tools

   3D Printing

   Administration Tools

   Authoring and Publishing

   Books and Guides

   Cloud Infrastructure

   Design Suite

   Editors

   Educational Software

   Electronic Lab

   Engineering and Scientific

   Fedora Eclipse

   Games and Entertainment

   Medical Applications

   Milkymist

   Network Servers

   Office/Productivity

   Robotics

   Security Lab

   Sound and Video

   Text-based Internet

   Window Managers

特别是上面的C开发和开发工具,偶觉得都是亮点。

 

 

 

 

ubuntu删除多余内核

ubuntu删除多余内核

如果升级到了一个新的内核,并且还比较稳定,那么老的内核就可以清理了,放在电脑里也占位置。方法(命令行比较通用)如下:

1.查看系统内存在的内核版本列表:

sudo dpkg –get-selections |grep linux

结果:

libselinux1                              install

linux-firmware                              install

linux-generic                                 install

linux-headers-3.2.0-33                       install

linux-headers-3.2.0-33-generic                install

linux-headers-3.2.0-33-generic-pae        install

linux-headers-3.2.0-34                       install

linux-headers-3.2.0-34-generic                install

linux-headers-3.2.0-34-generic-pae        install

linux-headers-3.2.0-35                       install

linux-headers-3.2.0-35-generic                install

linux-headers-3.2.0-35-generic-pae        install

linux-headers-3.2.0-37                       install

linux-headers-3.2.0-37-generic                install

linux-headers-3.2.0-37-generic-pae        install

linux-headers-3.2.0-38                       install

linux-headers-3.2.0-38-generic                install

linux-headers-3.2.0-38-generic-pae        install

linux-headers-3.2.0-40                       install

linux-headers-3.2.0-40-generic                install

linux-headers-3.2.0-40-generic-pae        install

linux-headers-generic                         install

linux-headers-generic-pae                 install

linux-image-2.6.32-21-generic                 deinstall

linux-image-2.6.32-40-generic                 deinstall

linux-image-2.6.32-41-generic                 deinstall

linux-image-2.6.32-42-generic                 install

linux-image-3.2.0-33-generic                   install

linux-image-3.2.0-34-generic                   install

linux-image-3.2.0-35-generic                   install

linux-image-3.2.0-37-generic                   install

linux-image-3.2.0-38-generic                   install

linux-image-3.2.0-40-generic                   install

linux-image-generic                            install

linux-libc-dev                                 install

linux-sound-base                          install

pptp-linux                               install

syslinux                                   install

syslinux-common                                install

syslinux-legacy                              install

util-linux                                  install

2.查看当前Ubuntu系统使用的内核版本

uname -a

结果:
Linux linux 3.2.0-40-generic #64-Ubuntu SMP Mon Mar 25 21:22:26 UTC 2013 i686 i686 i386 GNU/Linux

3.删除多余内核:
sudo apt-get purge

linux-image-2.6.32-21-generic linux-image-2.6.32-40-generic linux-image-2.6.32-41-generic linux-image-2.6.32-42-generic linux-image-3.2.0-33-generic linux-image-3.2.0-34-generic linux-image-3.2.0-35-generic linux-image-3.2.0-37-generic linux-image-3.2.0-38-generic

linux-headers-3.2.0-33 linux-headers-3.2.0-34 linux-headers-3.2.0-35 linux-headers-3.2.0-37 linux-headers-3.2.0-38

更新grub

sudo update-grub

再次查看一下内核列表,就发现旧版本已经不存在了!

install vncserver on ubuntu to realize the Graphical access

ubuntu安装vncserver实现图形化访问

Refer from: http://help.aliyun.com/manual?helpId=1371

请注意:

如果在安装中部分软件无法安装成功,说明软件源中缺包,先尝试使用命令#apt-get update更新软件源后尝试安装。如果还是不行,需要更换软件源。更换步骤:

a)输入命令#cp /etc/apt/sources.list /etc/apt/sources.list_backup

b)输入命令#vi /etc/apt/sources.list

c)添加其他软件源(推荐使用163、中科大、上海交大等速度较快的国内源)

d)保存并关闭窗口

e)输入命令:#apt-get update

 

 

下面我们开始安装了哦!

root账户名密码登陆后

1.ubuntu上安装vncserver,使用命令:# apt-get install vnc4server

clip_image001

clip_image002

clip_image003

2.开启vnc服务,输入命令:#vncserver

clip_image004

首次启动会要求设置密码,后面可以使用vncpasswd修改;

clip_image005

看到 New ‘****:1 (****)’ desktop is ****:1 (****代表主机名)即表示启动vnc成功,在主目录下产生一个.vnc目录;

clip_image006

3.在客户端下载“vnc客户端软件,进行链接

在服务器栏输入:ip1

clip_image007

clip_image008

输入用户名密码信息后,可以看到vnc连接页面

clip_image009

但是,这个页面好像不是我们想要的图形化界面。vncserver默认使用的窗口管理器是twm,这是一个很简陋的窗口管理器,下面我们把桌面改成GNOMEKDE

4. 备份原有xstartup文件: #cp ~/.vnc/xstartup  ~/.vnc/xstartup.bak

下面我们需要修改vnc启动文件,使用命令:#vi ~/.vnc/xstartup

打开后如下图所示

clip_image010

我们需要把上图中“x-window-manager &”这一行注释掉,然后在下面加入一行“gnome-session &”,或者是“startkde &”,分别启动GNOME桌面和KDE桌面。这里我们安装的是GNOME桌面。修改后如下图所示:(具体修改步骤:打开文件后,点击“insert”按钮,这时就可以输入了,在“x-window-manager &”前加“#”,然后回车输入“gnome-session &”,然后点击“Esc ”退出编辑模式,输入“:wq!”保存修改即可)

clip_image011

5.这时我们需要杀掉原桌面进程,输入命令:# vncserver -kill :1//这里的:1是桌面号

再次输入: #vncserver :1生成新的会话

clip_image012

6.下面我们开始安装gnome桌面环境

这里的安装有些慢,需要您耐心等待下。

(1)安装xwindows的基础 #sudo apt-get install x-window-system-core

clip_image013

(2)安装登录管理器:#sudo apt-get install gdm (还可以为kdm/xdm

clip_image014

(3)安装Ubuntu的桌面:#sudo apt-get install ubuntu-desktop(还可以为Kubunut-desktop/ Xubuntu-desktop

clip_image015

另外:

安装命令:apt-get install gnome-core可以安装GNOME的一些基础。apt-get install firefox/gaim/xmms可以安装 Firefox 浏览器、Gaim 聊天程序、XMMS 音乐播放器。您可以按照自己的喜好来安装。

 

7.下面我们重复步骤5, 输入命令:# vncserver -kill :1杀掉原桌面进程,

再次输入:#vncserver :1生成新的会话。然后使用vnc客户端连接,就可以看到图形化界面,如图:

clip_image016

 

注意:ubuntu10.10操作系统,安装后测试快捷键D无法正常使用,输入d时会使终端桌面显示、消失。这是因为快捷点冲突造成的(ubuntu 12.04无此问题)。

解决此问题,请按照以下步骤:

1)System->Preferences->Keyboard Shortcuts

找到系统快捷键设置菜单

clip_image017

 

2)打开快捷键设置对话框,并找到如下所示的条目,准备设置新的快捷键。\

clip_image018

 

3)  输入“Backspace”键,将这个快捷键Disable

clip_image019

 

4) 输入命令:# vncserver -kill :1杀掉原桌面进程, 再次输入:#vncserver :1生成新的会话。


5)
编辑/etc/rc.local在文件最后一行加入:
su root -c ‘/usr/bin/vncserver -name my-vnc-server -depth 16 -geometry 1280×800 :1’
即可实现开机自启动

 

install gtk on Ubuntu Distribution

ubuntu上安装gtk

Refer from: http://www.cnblogs.com/niocai/archive/2011/07/15/2107472.html

我利用此方法成功在UBUNTU 10.04下安装GTK 2.20.1

一、安装

  1、安装gcc/g++/gdb/make 等基本编程工具

$sudo apt-get install build-essential

  2、安装 libgtk2.0-dev libglib2.0-dev 等开发相关的库文件

$sudo apt-get install gnome-core-devel

  3、用于在编译GTK程序时自动找出头文件及库文件位置  

$sudo apt-get install pkg-config

  4、安装 devhelp GTK文档查看程序

$sudo apt-get install devhelp

  5、安装 gtk/glib API参考手册及其它帮助文档

$sudo apt-get install libglib2.0-doc libgtk2.0-doc

  6、安装基于GTK的界面GTK是开发Gnome窗口的c/c++语言图形库 

$sudo apt-get install glade libglade2-dev

或者

$sudo apt-get install glade-gnome glade-common glade-doc

  7、安装gtk2.0 或者 gtk+2.0所需的所有文件统通下载安装完毕

$sudo apt-get install libgtk2.0-dev

或者

$sudo apt-get install libgtk2.0*

  

二、查看GTK库版本

  1、查看1.2.x版本

$pkg-config –modversion gtk+

  2、查看 2.x 版本

$pkg-config –modversion gtk+-2.0

  3、查看pkg-config的版本

$pkg-config –version

  4、查看是否安装了gtk

$pkg-config –list-all grep gtk

  

三、测试程序

 

//Helloworld.c

#include <gtk/gtk.h>

int main(int argc,char *argv[])
{
    GtkWidget    *window;
    GtkWidget    *label;
   
    gtk_init(&argc,&argv);
   
   
/* create the main, top level, window */

    window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
   
   
/* give it the title */
    gtk_window_set_title(GTK_WINDOW(window),
“Hello World”);
   
   
/* connect the destroy signal of the window to gtk_main_quit
     * when the window is about to be destroyed we get a notification and
     * stop the main GTK+ loop
     */

    g_signal_connect(window,
“destroy”,G_CALLBACK(gtk_main_quit),NULL);
   
   
/* create the “Hello, World” label */

    label = gtk_label_new(
“Hello, World”);
   
   
/* and insert it into the main window */

    gtk_container_add(GTK_CONTAINER(window),label);
   
   
/* make sure that everything, window and label, are visible */
    gtk_widget_show_all(window);
   
   
/* start the main loop, and let it rest until the application is closed */
    gtk_main();
   
   
return 0
;
}

 

  

四、编译运行

  1、编译

$gcc -o Helloworld Helloworld.c `pkg-config –cflags –libs gtk+-2.0`

  2、运行

$./Helloworld