Linux server branding
OUTDATED PAGE...
This is quite a noob info for people who try to resell servers.
When you are reselling servers, you want to replace source company address by your address. What to edit?
List server specification, test network speed:
Additional IP add (source):ls -lt / /root;sleep 4;clear;hostname;cat /etc/red*;uname -a;sleep 3;mv /etc/resolv.conf /etc/resolv2.conf;echo -e "nameserver 8.8.8.8\nnameserver 8.8.4.4" > /etc/resolv.conf;cat /etc/resolv.conf;echo "Location:";wget -qO - https://ipinfo.io/$(curl ifconfig.io 2>/dev/null);sleep 4;ping google.com -c 3;sleep 4;w;echo "CPU name: $( awk -F: '/model name/ {name=$2} END {print name}' /proc/cpuinfo )";echo "CPU frequency: $( awk -F: ' /cpu MHz/ {freq=$2} END {print freq}' /proc/cpuinfo )Mhz x $( awk -F: '/model name/ {core++} END {print core}' /proc/cpuinfo ) cores";echo "Total RAM: $( free -m | awk 'NR==2 {print $2}' )";echo "Total SWAP: $( free -m | awk 'NR==4 {print $2}' )";sleep 6;lsblk -io KNAME,TYPE,SIZE,MODEL;df -h;sleep 6;cat /proc/mdstat;sleep 6;free -m;sleep 6;smartctl -H /dev/sda;sleep 6;smartctl -a /dev/sda;echo "Testing DL speed from Cachefly:";wget -O /dev/null http://cachefly.cachefly.net/100mb.test;read -r -p "Enter new hostname or hit enter to skip:" hn && if [[ "$hn" != "" ]]; then hostname "$hn" && hostnamectl set-hostname "$hn" && hostnamectl 2>/dev/null; fi;echo "Change password? -> passwd";echo "Delete secure log & history?";echo "cd /var/log;rm -rf audit;rm -f dmesg.*;rm -f messages-* cron-* maillog-* secure-* ~/.viminfo /var/log/http*/*log;[ -f auth.log ]&&>auth.log;[ -f messages ]&&>messages;[ -f maillog ]&&>maillog;[ -f cron ]&&>cron;[ -f secure ]&&>secure;[ -f wtmp ]&&>wtmp;[ -f btmp ]&&>btmp;[ -f dmesg ]&&>dmesg;[ -f lastlog ]&&>lastlog;[ -f syslog ]&&>syslog;[ -f lynis.log ]&&>lynis.log;[ -f fail2ban.log ]&&>fail2ban.log;>~/.bash_history;history -c;"
CentOS/Universal nmcli?
Debian/Ubuntu:read -r -p "Input IP address (including subnet, usually /24) to add as an additional IP to this system. Network will be restart after that:" addip && if [[ "$(ip a|grep -c $addip)" != 0 ]]; then echo "That IP may already be added, see "ip a" output." && exit; fi && sudo nmcli conn mod "System eth0" +ipv4.addresses "$addip" && systemctl restart network && echo "Ping that IP:" && ping -c2 $(echo $addip|sed -e 's/\/24//') && cd /var/log;rm -rf audit;rm -f dmesg.*;rm -f messages-* cron-* maillog-* secure-* ~/.viminfo /var/log/http*/*log;[ -f auth.log ]&&>auth.log;[ -f messages ]&&>messages;[ -f maillog ]&&>maillog;[ -f cron ]&&>cron;[ -f secure ]&&>secure;[ -f wtmp ]&&>wtmp;[ -f btmp ]&&>btmp;[ -f dmesg ]&&>dmesg;[ -f lastlog ]&&>lastlog;[ -f syslog ]&&>syslog;[ -f lynis.log ]&&>lynis.log;[ -f fail2ban.log ]&&>fail2ban.log;>~/.bash_history;history -c;
To change hostname at dedicated server, login via SSH (Command line interface - CLI), you can try software called PuTTY.read -r -p "Input IP address (including subnet, usually /24) to add as an additional IP to this system." addip && if [[ "$(ip a|grep -c $addip)" != 0 ]]; then echo "That IP may already be added, see "ip a" output." && exit; fi && apt -qqq install netplan.io && pubip="$(curl -4 ifconfig.co 2>/dev/null)" && for f in "$(grep -Ril $pubip /etc/netplan/)"; do sed -i "s|$pubip/24|$pubip/24\n$(printf '%.0s ' {0..11})- $addip|" "$f"; done && netplan generate && netplan apply; echo "Ping new IP:" && ping "$addip"
Then do command: hostname to learn your current one, then do hostname newhostname && hostnamectl set-hostname newhostname && hostnamectl 2>/dev/null
vi /etc/hosts
vi /etc/hostname
vi /etc/sysconfig/network
/etc/init.d/network restart (or: service networking --full-restart )
Some guide: OVH : ChangeServerName
Another files which may contain identifiable texts of company you are reselling:
postfix/main.cf
resolvconf/resolv.conf.d/original
resolv.conf
resolf.conf is how to setup networking on linux server, add:
search google.com
nameserver 8.8.8.8
nameserver 8.8.4.4
and /etc/init.d/network restart
vim /etc/postfix/main.cf - what is the use of this file? Its mail file, can i edit it?
Search in files content:
grep -rl "STRING THAT YOU WANT" *
Centos hostname change:
nhn="new.h.n" && ohn=$(hostname) && sed -i "s/$ohn/$nhn/g" /etc/sysconfig/network /etc/hosts;hostname $nhn;hostnamectl set-hostname $nhn 2>/dev/null
Clear acess logs of Ubuntu/CentOS server + command line history:
cd /var/log;rm -rf audit;rm -f dmesg.*;rm -f messages-* cron-* maillog-* secure-* ~/.viminfo /var/log/http*/*log;[ -f auth.log ]&&>auth.log;[ -f messages ]&&>messages;[ -f maillog ]&&>maillog;[ -f cron ]&&>cron;[ -f secure ]&&>secure;[ -f wtmp ]&&>wtmp;[ -f btmp ]&&>btmp;[ -f dmesg ]&&>dmesg;[ -f lastlog ]&&>lastlog;[ -f syslog ]&&>syslog;[ -f lynis.log ]&&>lynis.log;[ -f fail2ban.log ]&&>fail2ban.log;>~/.bash_history;history -c;
My initial server setup tasks here
Disk/net performance testing here
==================================
A message from Server4You
"How i can brand it to me, so i can sell it to some custommer while he not knowing im reselling your server?"
There should only be a few occurrences of server4you.net. Most if not all will occur in /etc. You can replace all occurrences automatically, off the top of my head, using a combination of "find" "xargs" and "sed"
" Also when i did traceroute on server, the serverhostname.server4you.net appeared, which i dont want to happen too."
Please see our last response:
i believe you mean the reverse dns, you can change that from your customer interface under Network >> Nameserver >> Reverse DNS.
---- Command to recursively replace hostname in /etc directory ----- (Not tried, be carefull)
Replace all occurances of oldstring with newstring in all files in current directory and its subdirectories?
find . -name '*' -type f -print0 | xargs -0 sed -i 's|oldhostname|newhostname|g'
above dont works when dot in phrasse?
Automated proces of replacing default server hostnameDO:
Use your CLI (command line), SSH:
(will create new file in /etc dir and open it) Then add following code into that file (copy there and then in Putty or similar SSH client do "A" key to enter editing mode. Then right mouse click. Then save the opened file with code you just pasted by shortcut: Ctrlcd /etc;vim search.sh
Above code is the search and replace script. DO one of next 2 commands to execute the script you created and search & replace in your server files your old hostname to new one.#!/bin/sh
grep -rl $2 $1 |
while read filename
do
(
echo $filename
sed "s/$2/$3/g;" $filename > $filename.xx
mv $filename.xx $filename
)
done
Here is the code which will execute above script and also delete script and clean user login history + clean history of commands. Search&replace may take 30 minutes
OPTION 1 (full server search&replace):
OPTION 2 (/etc directory search&replace):chmod 777 search.sh;./search.sh / oldhostname.olddomain.tld newhostname.newdomain.tld;./search.sh /etc oldhostname newhostname;rm -rf search.sh;history -c;echo >~/.bash_history;echo >/var/log/wtmp; echo > /var/log/btmp;>/var/log/lastlog;
done, you created search & replace script, you executed it, you deleted it after and you cleaned commands history and login history.chmod 777 search.sh;./search.sh /etc oldhostname.olddomain.tld newhostname.newdomain.tld;./search.sh /etc oldhostname newhostname;rm -rf search.sh;history -c;echo >~/.bash_history;echo >/var/log/wtmp; echo > /var/log/btmp;>/var/log/lastlog;
Bookmarks