Linux network, x11vnc, virtualbox, useful commands.

Persistent config:
# vi /etc/network/interfaces
up route add -net netmask gw
down route del -net netmask gw

Generic method to add persistent static routing on Linux
# vi /etc/rc.local
Append the following line:
/sbin/ip route add dev eth0
/sbin/ip route add dev eth0
route add default gw

# vi /etc/rc.local
route add -net netmask gw

traceroute is a tool used to identify the path used by a packet to reach the destination. …
The traceroute command is available on most modern operating systems (Windows, Apple Mac OS, Unix, Linux, etc). traceroute usually works by sending a series of ICMP echo request packets to a destination.

1.ifconfig -a
cat /etc/resolv.conf œ‹ip/netmask/’Œdns
2.netstat -rn /etc/sysconfig/network /etc/sysconfig/network-scripts/ifcfg-eth0
6.ip route show
7.route -n

方法二:$sudo /etc/init.d/nscd restart
或者:$service nscd restart
或者:$service nscd reload
如果nscd无法执行,先安装nscd,命令如下:$sudo apt-get install nscd

chmod a+rwx : set the last 3 octals to 777, so it ensure that Owner, Group and Users have the “rwx” set. If there was aditionnal bits in the first octal (setuid, setgid, and/or Sticky bit) it leaves them untouched.
There are three major types of file permissions:
User permissions. These permissions apply to a single user who has special access to the file. This user is called the owner.
Group permissions. These apply to a single group of users who have access to the file. This group is the owning group.
Other permissions. These apply to every other user on the system. These users are known as others, or the world.

You can do this:
1st way:
ls -l /path/to/file
the third field in the ls -l output is the user and the fourth is the group
2nd way:
stat /path/to/file

sudo chown notme:notmygroup myfile.txt
sudo chown -R myuser:mygroup otherfiles
The above command will change the ownership of every file, subdirectory, and subdirectory contents in otherfiles.

Linux: List all members of a group using /etc/group file
Use the grep command as follows:
$ grep ‘grpup-name-here’ /etc/group
$ grep ‘ftponly’ /etc/group
$ grep -i –color ‘ftponly’ /etc/group

GRUB 所使用的硬盘/分区命名约定与 Linux 使用的命名约定不同。在 Linux 中,第一个硬盘的第五个分区称作 “hda5″。而 GRUB 把这个分区称作 “(hd0,4)”。
调整当前 root 命令行,以使它指向保存 Linux 内核的分区。按以下格式输完命令,然后按 Enter 键:
grub> root (hd0,4)
可以在 GRUB 中使用它来引导 Linux 发行版,操作如下:
grub> root (fd0)
grub> kernel /boot/bzImage root=/dev/hda5 (将 /dev/hda5 更改成想要引导的分区名称)
grub> boot
一个简单的文本文件 menu.lst:
default 0
timeout 30
color white/blue blue/green

title=Boot Linux
root (hd0,4)
kernel /boot/bzImage root=/dev/hda5

title=Boot Linux using initrd
root (hd0,5)
kernel /boot/bzImage root=/dev/loop0 init=/initdisk.gz
initrd /initdisk.gz

title=Windows NT
root (hd0,3)
chainloader +1

C:\grldr=linux boot
color black/cyan yellow/cyan
timeout 5
default /default
title Red Hat Enterprise Linux Server (2.6.18-53.el5)
root (hd0,7)
kernel /boot/vmlinuz-2.6.18-53.el5 ro root=LABEL=/ rhgb quiet
initrd /boot/initrd-2.6.18-53.el5.img

A jump server is an intermediary server through which external agents, such as Venafi Encryption Director, can access a device behind a firewall.
If a jump server is required to access a device behind a firewall, the Jump Server object provides the information Venafi Encryption Director needs to communicate with the target device(s) via the jump server.
Jump server may use either username and password or private key for authentication. The target device and application can’t use private key for authentication.

A jump server can be useful when it’s a sort of privileged access proxy. That is, I connect to it as a normal user, and it does whatever I ask it to using elevated privileges that only last for the duration of my stay.

To fix this problem you need to have another computer, which is publicly accessible and have SSH access to it. It can be any server on the internet, as long as you can connect to it.
We’ll tell SSH to make a tunnel that opens up a new port on the server, and connects it to a local port on your machine.
$ ssh -R 9000:localhost:3000
The syntax here is very similar to local port forwarding, with a single change of -L for -R. But as with local port forwarding, the syntax remains the same.
First you need to specify the port on which th remote server will listen, which in this case is 9000, and next follows localhost for your local machine, and the local port, which in this case is 3000.
There is one more thing you need to do to enable this. SSH doesn’t by default allow remote hosts to forwarded ports. To enable this open /etc/ssh/sshd_config and add the following line somewhere in that config file.
GatewayPorts yes

$ pgrep x11v -a
3446 x11vnc -gui tray=setpass -rfbport PROMPT -bg -o %HOME/.x11vnc.log.%VNCDISPLAY

$ ss -ltn
$ ss -ltp
$ netstat -ltn
$ netstat -ltp

1、在Windows上用记事本把文件,选择另存为编码方式改为 UTF-8;
:set fileencoding=utf-8
3、iconv 转换,iconv的命令格式如下:
iconv -f encoding -t encoding inputfile
iconv -f UTF-8 -t GBK file1 -o file2

install mongodb on ubuntu:
/usr/bin/mongod –unixSocketPrefix=/run/mongodb –config /etc/mongodb.conf
bind_ip is necessary, otherwise mongo doesn’t work.
bind_ip = (local address)
#bind_ip =
#port = 27017
ufw allow 27017
sudo service mongodb stop | sudo service mongodb start

sudo apt-get install ifconfig
Error: unable to locate ifconfig
=> sudo apt install net-tools.

RealVNC Viewer vs tigerVNC viewer
Install openssh-server on MiniServer, allow port 22, then i can access it via ssh.

sudo apt-get install x11vnc
sudo x11vnc -storepasswd

sudo nano /lib/systemd/system/x11vnc.service
Description=Start x11vnc at startup.
ExecStart=/usr/bin/x11vnc -auth guess -once -loop -noxdamage -repeat -rfbauth /home/USERNAME/.vnc/passwd -rfbport 5900 -shared

$ sudo systemctl daemon-reload
$ sudo systemctl enable x11vnc.service
$ x11vnc

#ss -ltn
#netstat -ltn
Remove the default Vino server:
sudo apt-get -y remove vino

Ubuntu Setting -> Share -> Enable RemoteDesktop. (Necessary?)
=> Then i can see port 5900 opened.


/etc/rc.local 不执行的问题汇总
#chmod +x /etc/rc.local
# rm -rf /etc/rc.local
# ln -s /etc/rc.d/rc.local /etc/rc.local

start on login-session-start
x11vnc -display :0 -auth /var/run/lightdm/root/:0 -forever -bg -o /var/log/x11vnc.log -rfbauth /etc/x11vnc.pass -rfbport 5900
x11vnc -display :0 -auth guess -once -loop -noxdamage -repeat -rfbauth /home/wtong/.vnc/passwd -rfbport 5900 -shared
end script

=>Still a problem.

$ sudo dpkg -L x11vnc

su为switch user,即切换用户的简写
su [user]切换到其他用户,但是不切换环境变量,su – [user]则是完整的切换到新的用户环境。

Add vitualbox source to APT sourcelist, then update.
$sudo apt-get update
Skipping acquire of configured file ‘contrib/binary-i386/Packages’ as repository
‘ bionic InRelease’ doesn’t support architecture ‘i386’
sudo nano /etc/apt/sources.list.d/virtualbox.list
and change:
deb bionic contrib
deb [arch=amd64] bionic contrib
Or open terminal an execute the following command:
echo “deb [arch=amd64] $(lsb_release -sc) contrib” | sudo tee /etc/apt/sources.list.d/virtualbox.list
SOLUTION : limit to just 64 bit by introducing the [arch=amd64]

$ dpkg –print-architecture
$ lsb_release -cs

Install Virtualbox-5.2 on Ubuntu 1804
$ sed -i ‘$adeb [arch=amd64] bionic contrib’ /etc/apt/sources.list
$ sudo add-apt-repository “deb `lsb_release -cs` contrib”
deb [arch=amd64] bionic contrib
# deb-src bionic contrib
$ wget -q -O- | sudo apt-key add –
$ wget -q -O- | sudo apt-key add –
通过apt安装VirtualBox和dkms,其中dkms包可以确保在下次通过apt upgrade更新内核时,VirtualBox的内核模块也正确地更新:
$ sudo apt-get update
$ sudo apt-get install virtualbox-5.2

Download Centos Images:
4G DVD + 960M Minimal

$ sudo shutdown -P –no-wall 150
Shutdown scheduled for Thu 2018-12-06 10:44:27 CST, use ‘shutdown -c’ to cancel.

Install stress-ng on Debian and Ubuntu:
sudo apt-get install stress-ng

Hardinfo can be grabbed on most distros using the native package manager, but I find it easiest to just run this command on Debian and Ubuntu:
sudo apt-get install hardinfo


# locate virtualbox | grep .iso
点击 VirtualBox 菜单栏中的【设备】->【分配光驱】->【选择虚拟盘】->【定位到 VirtualBox 安装目录】->【选择 VBoxGuestAdditions.iso】,
挂载光驱到 tmp 目录 !!! 核心步骤!!!
[root@localhost ~] mount /dev/cdrom /tmp/  # 这时会提示目录挂载成功且为ready-only
[root@localhost ~] cp -r /tmp/ /mnt/      # 把挂载目录复制到另外一个文件夹,这样才能执行写操作
[root@localhost ~] cd /mnt/tmp
[root@localhost tmp] ./  # 执行安装
然后,就会发现其中的菜单项“Switch to Seamless Mode(虚拟显示屏)”可以使用了

yum -y install kmod-fglrx
1024*768 60Hz
800*600 60Hz

首先进入虚拟机,然后按你的Host key+Home键,就会弹出菜单栏,然后选择Switch to scale mode,隐藏的菜单就会重新显示了。
如果你觉得这样有些麻烦,可以直接按Host key+C,也能达到同样的效果。

RedHat、RHEL:rpm -i vh *.rpm
Ubuntu安装:sudo dpkg -i *.deb

1、yum -y update
2、yum -y install g++ gcc gcc-c++ make kernel-* # 主要是在安装增强工具提示没有安装这些软件
3、yum -y install bzip2* # 增强工具用的是bzip2压缩

yum groupinstall “Development Tools”
yum install kernel-devel kernel-devel-3.10.0-957.el7.x86_64 (According to VBoxLinux… prompt)
yum install kernel-headers


$ vi /etc/sysconfig/network-scripts/ifcfg-enp0s3
$ vi /etc/sysconfig/network
$ vi /etc/resolv.cof

$ tightvncserver -kill :1
$ tightvncserver

sudo apt-get install xfonts-100dpi
sudo apt-get install xfonts-75dpi
NOT WORK for tightvncserver, so use back to x11vnc.
$ sudo apt-get purge tightvncserver

apt-get remove 会删除软件包而保留软件的配置文件
apt-get purge 会同时清除软件包和软件的配置文件