Ubuntu/Quick Reference

From r00tedvw.com wiki
(Difference between revisions)
Jump to: navigation, search
(Ubuntu Desktop 14.04 - unable to resolve hostnames except through dig)
Line 187: Line 187:
 
  <nowiki>hosts: dns files wins</nowiki>
 
  <nowiki>hosts: dns files wins</nowiki>
 
Rebooted and now everything works.
 
Rebooted and now everything works.
 +
 +
==Expand root disk on VM==
 +
In this scenario, I needed to expand the disk on a non-LVM ubuntu installation.  Nothing particularly special about this setup thankfully, just has the default partition configuration:
 +
<nowiki>~$ fdisk -l
 +
....
 +
Device    Boot    Start      End  Sectors Size Id Type
 +
/dev/sda1  *        2048 75497471 75495424  36G 83 Linux
 +
/dev/sda2      75499518 83884031  8384514  4G  5 Extended
 +
/dev/sda5      75499520 83884031  8384512  4G 82 Linux swap / Solaris</nowiki>
 +
===Expand disk in hypervisor===
 +
To start things off, we need to expand the disk in the hypervisor.  In my case I was using SCVMM atop Hyper-V, so I just powered off the virtual machine > VM properties > hardware configuration > Disk > Expand virtual disk.<br>
 +
Your hypervisor may be different.<br>
 +
<br>
 +
Confirm the disk has been expanded (but filesystem has not been).  Notice in this example <code>/dev/sda</code> is 100GB.
 +
<nowiki>~$ sudo lsblk
 +
NAME  MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
 +
fd0      2:0    1    4K  0 disk
 +
sda      8:0    0  100G  0 disk
 +
├─sda1  8:1    0  38G  0 part /
 +
├─sda2  8:2    0    1K  0 part
 +
└─sda5  8:5    0    2G  0 part [SWAP]
 +
sr0    11:0    1 1024M  0 rom</nowiki>
 +
 +
===Disable swap and remove partitions===
 +
With the root partition starting from the beginning of the disk, in order to expand it the swap partition has to be deleted and recreated.  Thankfully since the swap should not be mounted, this is pretty easy.
 +
<nowiki> ~$ sudo swapoff -a
 +
~$ sudo lsblk
 +
NAME  MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
 +
fd0      2:0    1    4K  0 disk
 +
sda      8:0    0  100G  0 disk
 +
├─sda1  8:1    0  38G  0 part /
 +
├─sda2  8:2    0    1K  0 part
 +
└─sda5  8:5    0    2G  0 part
 +
sr0    11:0    1 1024M  0 rom</nowiki>
 +
Before we can delete the swap partition(s), we need to discover the disk name and the partition number(s)
 +
<nowiki>~$ sudo parted -l
 +
Model: Msft Virtual Disk (scsi)
 +
Disk /dev/sda: 107GB
 +
Sector size (logical/physical): 512B/4096B
 +
Partition Table: msdos
 +
Disk Flags:
 +
 +
Number  Start  End    Size    Type      File system    Flags
 +
1      1049kB  40.8GB  40.8GB  primary  ext4            boot
 +
2      40.8GB  42.9GB  2145MB  extended
 +
5      40.8GB  42.9GB  2145MB  logical  linux-swap(v1)</nowiki>
 +
Now we can delete the swap(s).
 +
<nowiki>~$ sudo parted /dev/sda rm 2
 +
Information: You may need to update /etc/fstab.</nowiki>
 +
Since the logical is within the extended partition, when you remove it, it removes both.<br>
 +
If you needed to check for mounts on the partition, you could use <code>mount</code>
 +
<nowiki>~$ sudo mount
 +
sysfs on /sys type sysfs (rw,nosuid,nodev,noexec,relatime)
 +
proc on /proc type proc (rw,nosuid,nodev,noexec,relatime)
 +
udev on /dev type devtmpfs (rw,nosuid,relatime,size=1000664k,nr_inodes=250166,mode=755)
 +
...</nowiki>
 +
 +
===Extend root partition===
 +
'''WARNING:''' the following section is '''HACKY''' to say the least.  Unfortunately i dont know a better way of doing it yet.
 +
 +
===Create new swap partitions===
 +
Before we can grow the primary partition, we need to recreate our swap partition(s).  We are going to setup a new Extended partition at the new end of the disk.  I've chosen 2GB as my RAM is set to 2GB.
 +
<nowiki>~$ sudo parted -s /dev/sda unit GiB mkpart extended 98GiB 100%
 +
~$ sudo parted -l
 +
Model: Msft Virtual Disk (scsi)
 +
Disk /dev/sda: 107GB
 +
Sector size (logical/physical): 512B/4096B
 +
Partition Table: msdos
 +
Disk Flags:
 +
 +
Number  Start  End    Size    Type      File system  Flags
 +
1      1049kB  40.8GB  40.8GB  primary  ext4        boot
 +
2      105GB  107GB  2147MB  extended              lba
 +
 +
 +
 +
sudo parted -s -a optimal /dev/sda unit s mkpart logical linux-swap 205520897 100%

Revision as of 02:37, 14 September 2019

Contents

Enable Remote Desktop via VNC (12.04+ - these are just default, you may want to configure more)

Dash Home > [type] Desktop > [Select] either Desktop Sharing or Remote Desktop
[check] Allow view and control > [check] require user to enter password > [type] password

Upgrade from 10.04LTS to 12.04LTS via terminal

$ sudo apt-get update
$ sudo apt-get install update-manager-core
$ sudo vi /etc/update-manager/release-upgrades
verify there is the following line in the file
prompt=lts
$ sudo apt-get update && sudo apt-get -y upgrade && sudo apt-get -y autoremove
$ sudo do-release-upgrade -d

rename directory with contents

~$ sudo mv -f /path/oldfolderanem /path/newfoldername

ubuntu 14.04 apt-get error

W: GPG error: http://archive.ubuntu.com trusty Release: The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 40976EAF437D05B5 NO_PUBKEY 3B4FE6ACC0B21F32

Keys are:

40976EAF437D05B5
3B4FE6ACC0B21F32

fix by importing keys from Canonical's key library:

~$sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 3B4FE6ACC0B21F32
~$sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 40976EAF437D05B5

ubuntu 14.04 locale error

error
perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
	LANGUAGE = (unset),
	LC_ALL = (unset),
	LANG = "en_US.UTF-8"
    are supported and installed on your system.
perl: warning: Falling back to the standard locale ("C").
solution

1. check what locales you have available on the machine

~$ locale -a
locale: Cannot set LC_CTYPE to default locale: No such file or directory
locale: Cannot set LC_MESSAGES to default locale: No such file or directory
locale: Cannot set LC_COLLATE to default locale: No such file or directory
C
C.UTF-8
POSIX

2. if you're missing the locale for your area like i was, you can sometimes discover the name

~$ locale
locale: Cannot set LC_CTYPE to default locale: No such file or directory
locale: Cannot set LC_MESSAGES to default locale: No such file or directory
locale: Cannot set LC_ALL to default locale: No such file or directory
LANG=en_US.UTF-8
LANGUAGE=
LC_CTYPE="en_US.UTF-8"
LC_NUMERIC="en_US.UTF-8"
LC_TIME="en_US.UTF-8"
LC_COLLATE="en_US.UTF-8"
LC_MONETARY="en_US.UTF-8"
LC_MESSAGES="en_US.UTF-8"
LC_PAPER="en_US.UTF-8"
LC_NAME="en_US.UTF-8"
LC_ADDRESS="en_US.UTF-8"
LC_TELEPHONE="en_US.UTF-8"
LC_MEASUREMENT="en_US.UTF-8"
LC_IDENTIFICATION="en_US.UTF-8"
LC_ALL=

3. once you know which locale you need, you can build it

~$ sudo locale-gen en_US.UTF-8
Generating locales...
  en_US.UTF-8... done
Generation complete.

4. make sure it's up to date (which is should be)

~$ sudo dpkg-reconfigure locales
Generating locales...
  en_US.UTF-8... up-to-date
Generation complete.

5. check to see if the new locale is listed and verify you no longer get the error

~$ locale -a
C 
C.UTF-8
en_US.utf8
POSIX

You'll see here that unlike in step 1, you get the required responses without an error message.

search for directories recursively and add execute permission

~$ find /var/www/mysite.com/ -type d -exec chmod+x {} \;


port scan from behind a firewall to determine which ports are open

first, there are a couple of things you'll need:

  1. linux box inside the firewall with nmap installed
  2. linux box outside the firewall with tcpdump installed


essentially, we are going to use nmap to port scan the box outside the firewall from inside, then look at the tcpdump logs and determine which packets got there and what ports they were destined for.

setup tcpdump

setup tcpdump to capture the traffic on the outside box

~$ tcpdump -i <interface> -n <source>
i.e. ~$ sudo tcpdump -i venet0:0 -n "src host 8.8.8.8 and not (dst port 80 or dst port 443)" -w port_scan.cap

In my example above, i went 1 extra step and said not to capture any packets going to port 80 or 443. I did this because I saw my firewall had a nifty little feature where it redirected traffic for restricted ports to 80 and 443, so because I already knew these were open, I could determine that any traffic hitting these ports was from redirected blocked ports.

scan with nmap

use nmap from the inside box

~$ nmap -p 1-65535 8.8.8.8

Simple nmap scan of all ports from 1 to 65535 (which are all available ports). The wildcard scan "*" didnt work as well as this did and i got a few more results.

parse the pcap

Once your nmap is done, now we can go back to our box on the outside, stop the tcpdump and start parsing it.

convert to txt
first lets convert the pcap to txt
~$ tcpdump -n -r portscan.cap > port_scan.txt
look at the txt
really quickly, this is an example of the txt output from our pcap
03:43:59.008245 IP 4.2.2.2.53008 > 8.8.8.8.10443: Flags [S], seq 1225698019, win 14600, options [mss 1380,sackOK,TS val 153049091 ecr 0,nop,wscale 7], length 0
parse the txt
now lets extract just the port numbers we care about
~$awk '{print $5;}' port_scan.txt  | sed 's/8.8.8.8.//g' | sed 's/://g'

To break down the example above:

  1. awk uses whitespaces as delimiters by default, so its easy to see the 2nd IP listed with the port is the 5th object.
  2. the first sed then looks for the outside box's IP, and replaces it with nothing (deleting it)
  3. the second sed cleans it up by replacing the colon after the port with nothing (deleting it)


results

So in the end, you end up with a nice list of open ports, like such:

~$ awk '{print $5;}' port_scan.txt  | sed 's/8.8.8.8.//g' | sed 's/://g'
22
8080
22
22
8173
8173
43
43
5050
5050
15210
15210
1003
1003
8082
10443
10443

Spoof MAC address and connect to network without rebooting

Took me awhile to figure out what series of events would allow me to spoof a MAC address, obtain a new DHCP lease and IP address, and connect to the network without rebooting. Turns out it was super simple.
If ifdown doesn't work and says something about interface eth0 not configured, try rebooting. Even a fresh install of 14.04 encountered this issue.

turn down interface
~$ sudo ifdown eth0
spoof MAC
~$ sudo ifconfig eth0 hw ether xx:xx:xx:xx:xx:xx
turn up interface
~$ sudo ifup eth0

From here if you run ifconfig you should see your interface with the new MAC address and DHCP lease with IP address.

find network settings of local interface

~$ nm-tool

NetworkManager Tool

State: connected (global)

- Device: eth1  [Wired connection 2] -------------------------------------------
  Type:              Wired
  Driver:            r8169
  State:             connected
  Default:           yes
  HW Address:        00:11:22:33:44:55

  Capabilities:
    Carrier Detect:  yes
    Speed:           1000 Mb/s

  Wired Properties
    Carrier:         on

  IPv4 Settings:
    Address:         10.0.0.241
    Prefix:          24 (255.255.255.0)
    Gateway:         10.0.0.3

    DNS:             10.0.0.3
    DNS:             127.0.0.1

Ubuntu Desktop 14.04 - unable to resolve hostnames except through dig

Weird issue, after setting up a local Zentyal server with DNS enabled, I could look up the DNS records I created by using dig, but any other commands, like ping, would not resolve the hostname. Neither would any browsers.
I found out that my /etc/nsswitch.conf file had this setup for hosts:

hosts: files mdns4_minimal [NOTFOUND=return] dns

So I changed it to this:

hosts: dns files wins

Rebooted and now everything works.

Expand root disk on VM

In this scenario, I needed to expand the disk on a non-LVM ubuntu installation. Nothing particularly special about this setup thankfully, just has the default partition configuration:

~$ fdisk -l
....
Device     Boot    Start      End  Sectors Size Id Type
/dev/sda1  *        2048 75497471 75495424  36G 83 Linux
/dev/sda2       75499518 83884031  8384514   4G  5 Extended
/dev/sda5       75499520 83884031  8384512   4G 82 Linux swap / Solaris

Expand disk in hypervisor

To start things off, we need to expand the disk in the hypervisor. In my case I was using SCVMM atop Hyper-V, so I just powered off the virtual machine > VM properties > hardware configuration > Disk > Expand virtual disk.
Your hypervisor may be different.

Confirm the disk has been expanded (but filesystem has not been). Notice in this example /dev/sda is 100GB.

~$ sudo lsblk
NAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
fd0      2:0    1    4K  0 disk
sda      8:0    0  100G  0 disk
├─sda1   8:1    0   38G  0 part /
├─sda2   8:2    0    1K  0 part
└─sda5   8:5    0    2G  0 part [SWAP]
sr0     11:0    1 1024M  0 rom

Disable swap and remove partitions

With the root partition starting from the beginning of the disk, in order to expand it the swap partition has to be deleted and recreated. Thankfully since the swap should not be mounted, this is pretty easy. ~$ sudo swapoff -a ~$ sudo lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT fd0 2:0 1 4K 0 disk sda 8:0 0 100G 0 disk ├─sda1 8:1 0 38G 0 part / ├─sda2 8:2 0 1K 0 part └─sda5 8:5 0 2G 0 part sr0 11:0 1 1024M 0 rom Before we can delete the swap partition(s), we need to discover the disk name and the partition number(s)

~$ sudo parted -l
Model: Msft Virtual Disk (scsi)
Disk /dev/sda: 107GB
Sector size (logical/physical): 512B/4096B
Partition Table: msdos
Disk Flags:

Number  Start   End     Size    Type      File system     Flags
 1      1049kB  40.8GB  40.8GB  primary   ext4            boot
 2      40.8GB  42.9GB  2145MB  extended
 5      40.8GB  42.9GB  2145MB  logical   linux-swap(v1)

Now we can delete the swap(s).

~$ sudo parted /dev/sda rm 2
Information: You may need to update /etc/fstab.

Since the logical is within the extended partition, when you remove it, it removes both.
If you needed to check for mounts on the partition, you could use mount

~$ sudo mount
sysfs on /sys type sysfs (rw,nosuid,nodev,noexec,relatime)
proc on /proc type proc (rw,nosuid,nodev,noexec,relatime)
udev on /dev type devtmpfs (rw,nosuid,relatime,size=1000664k,nr_inodes=250166,mode=755)
...

Extend root partition

WARNING: the following section is HACKY to say the least. Unfortunately i dont know a better way of doing it yet.

Create new swap partitions

Before we can grow the primary partition, we need to recreate our swap partition(s). We are going to setup a new Extended partition at the new end of the disk. I've chosen 2GB as my RAM is set to 2GB.

~$ sudo parted -s /dev/sda unit GiB mkpart extended 98GiB 100%
~$ sudo parted -l
Model: Msft Virtual Disk (scsi)
Disk /dev/sda: 107GB
Sector size (logical/physical): 512B/4096B
Partition Table: msdos
Disk Flags:

Number  Start   End     Size    Type      File system  Flags
 1      1049kB  40.8GB  40.8GB  primary   ext4         boot
 2      105GB   107GB   2147MB  extended               lba



sudo parted -s -a optimal /dev/sda unit s mkpart logical linux-swap 205520897 100%
Personal tools
Namespaces

Variants
Actions
Navigation
Mediawiki
Confluence
DevOps Tools
Ubuntu
Oracle Linux
AWS
Windows
OpenVPN
Grafana
Pivotal
osTicket
OTRS
phpBB
WordPress
VmWare ESXI 5.1
Crypto currencies
HTML
CSS
Python
Java Script
PHP
Raspberry Pi
Canvas LMS
Kaltura Media Server
MetaSploit
Zoneminder
Photoshop CS2
Fortinet
Uploaded
Certifications
General Info
Games
Meal Plans
NC Statutes
Toolbox