Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
[SOLVED] Can't Change Hostname
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Other Things Gentoo
View previous topic :: View next topic  
Author Message
somethin
n00b
n00b


Joined: 19 Jan 2016
Posts: 37

PostPosted: Tue Jan 19, 2016 1:42 pm    Post subject: [SOLVED] Can't Change Hostname Reply with quote

Code:
wronghost / # hostname
wronghost
wronghost / #

I tried to run "hostname -F /etc/hostname", "sysctl kernel.hostname=righthost", tried adding "send host-name "righthost"" to /etc/dhcp/dhclient, tried switching to dhcpcd, but after reboot hostname is "wronghost". I don't know what to do.
Code:

wronghost / # emerge --info
Portage 2.2.27 (python 2.7.11-final-0, default/linux/amd64/13.0/desktop/plasma, gcc-5.3.0, glibc-2.22-r1, 4.4.0-gentoo x86_64)
=================================================================
System uname: Linux-4.4.0-gentoo-x86_64-Intel-R-_Core-TM-_i5-4460_CPU_@_3.20GHz-with-gentoo-2.2
KiB Mem:     8103604 total,   6635572 free
KiB Swap:    8388604 total,   8388604 free
Timestamp of repository gentoo: Tue, 19 Jan 2016 00:45:01 +0000
sh bash 4.3_p42-r1
ld GNU ld (Gentoo 2.25.1 p1.1) 2.25.1
app-shells/bash:          4.3_p42-r1::gentoo
dev-lang/perl:            5.22.1::gentoo
dev-lang/python:          2.7.11-r2::gentoo, 3.4.3-r7::gentoo
dev-util/cmake:           3.4.1::gentoo
dev-util/pkgconfig:       0.29::gentoo
sys-apps/baselayout:      2.2::gentoo
sys-apps/openrc:          0.20.2::gentoo
sys-apps/sandbox:         2.10-r1::gentoo
sys-devel/autoconf:       2.13::gentoo, 2.69-r1::gentoo
sys-devel/automake:       1.13.4-r1::gentoo, 1.14.1-r1::gentoo, 1.15-r1::gentoo
sys-devel/binutils:       2.25.1-r1::gentoo
sys-devel/gcc:            5.3.0::gentoo
sys-devel/gcc-config:     1.8::gentoo
sys-devel/libtool:        2.4.6-r1::gentoo
sys-devel/make:           4.1-r1::gentoo
sys-kernel/linux-headers: 4.4::gentoo (virtual/os-headers)
sys-libs/glibc:           2.22-r1::gentoo
Repositories:

gentoo
    location: /usr/portage
    sync-type: rsync
    sync-uri: rsync://rsync.gentoo.org/gentoo-portage
    priority: -1000

ACCEPT_KEYWORDS="amd64 ~amd64"
ACCEPT_LICENSE="* -@EULA"
CBUILD="x86_64-pc-linux-gnu"
CFLAGS="-march=native -O2 -pipe"
CHOST="x86_64-pc-linux-gnu"
CONFIG_PROTECT="/etc /usr/share/config /usr/share/gnupg/qualified.txt"
CONFIG_PROTECT_MASK="/etc/ca-certificates.conf /etc/dconf /etc/env.d /etc/fonts/fonts.conf /etc/gconf /etc/gentoo-release /etc/revdep-rebuild /etc/sandbox.d /etc/terminfo"
CXXFLAGS="-march=native -O2 -pipe"
DISTDIR="/usr/portage/distfiles"
FCFLAGS="-O2 -pipe"
FEATURES="assume-digests binpkg-logs config-protect-if-modified distlocks ebuild-locks fixlafiles merge-sync news parallel-fetch preserve-libs protect-owned sandbox sfperms strict unknown-features-warn unmerge-logs unmerge-orphans userfetch userpriv usersandbox usersync xattr"
FFLAGS="-O2 -pipe"
GENTOO_MIRRORS="http://distfiles.gentoo.org"
LANG="en_US.utf8"
LDFLAGS="-Wl,-O1 -Wl,--as-needed"
MAKEOPTS="-j5"
PKGDIR="/usr/portage/packages"
PORTAGE_CONFIGROOT="/"
PORTAGE_RSYNC_OPTS="--recursive --links --safe-links --perms --times --omit-dir-times --compress --force --whole-file --delete --stats --human-readable --timeout=180 --exclude=/distfiles --exclude=/local --exclude=/packages --exclude=/.git"
PORTAGE_TMPDIR="/var/tmp"
USE="X a52 aac acl acpi alsa amd64 berkdb bindist bluetooth branding bzip2 cairo cdda cdr cli consolekit cracklib crypt cups cxx dbus declarative dri dts dvd dvdr emboss encode exif fam firefox flac fortran gdbm gif glamor gpm gtk iconv ipv6 jpeg kde kipi lcms ldap libnotify mad mmx mmxext mng modules mp3 mp4 mpeg multilib ncurses nls nptl ogg opengl openmp pam pango pcre pdf phonon plasma png policykit ppds qml qt3support qt4 qt5 readline sdl seccomp semantic-desktop session spell sse sse2 ssl startup-notification svg tcpd tiff truetype udev udisks unicode upower usb vorbis widgets wxwidgets x264 xattr xcb xcomposite xinerama xml xscreensaver xv xvid zlib" ABI_X86="64" ALSA_CARDS="ali5451 als4000 atiixp atiixp-modem bt87x ca0106 cmipci emu10k1x ens1370 ens1371 es1938 es1968 fm801 hda-intel intel8x0 intel8x0m maestro3 trident usb-audio via82xx via82xx-modem ymfpci" APACHE2_MODULES="authn_core authz_core socache_shmcb unixd actions alias auth_basic authn_alias authn_anon authn_dbm authn_default authn_file authz_dbm authz_default authz_groupfile authz_host authz_owner authz_user autoindex cache cgi cgid dav dav_fs dav_lock deflate dir disk_cache env expires ext_filter file_cache filter headers include info log_config logio mem_cache mime mime_magic negotiation rewrite setenvif speling status unique_id userdir usertrack vhost_alias" CALLIGRA_FEATURES="kexi words flow plan sheets stage tables krita karbon braindump author" CAMERAS="ptp2" COLLECTD_PLUGINS="df interface irq load memory rrdtool swap syslog" CPU_FLAGS_X86="aes avx avx2 fma3 mmx mmxext popcnt sse sse2 sse3 sse4_1 sse4_2 ssse3" ELIBC="glibc" GPSD_PROTOCOLS="ashtech aivdm earthmate evermore fv18 garmin garmintxt gpsclock itrax mtk3301 nmea ntrip navcom oceanserver oldstyle oncore rtcm104v2 rtcm104v3 sirf superstar2 timing tsip tripmate tnt ublox ubx" GRUB_PLATFORMS="efi-64" INPUT_DEVICES="evdev" KERNEL="linux" LCD_DEVICES="bayrad cfontz cfontz633 glk hd44780 lb216 lcdm001 mtxorb ncurses text" LIBREOFFICE_EXTENSIONS="presenter-console presenter-minimizer" OFFICE_IMPLEMENTATION="libreoffice" PHP_TARGETS="php5-5" PYTHON_SINGLE_TARGET="python2_7" PYTHON_TARGETS="python2_7 python3_4" RUBY_TARGETS="ruby20 ruby21" USERLAND="GNU" VIDEO_CARDS="nvidia" XTABLES_ADDONS="quota2 psd pknock lscan length2 ipv4options ipset ipp2p iface geoip fuzzy condition tee tarpit sysrq steal rawnat logmark ipmark dhcpmac delude chaos account"
Unset:  CC, CPPFLAGS, CTARGET, CXX, EMERGE_DEFAULT_OPTS, INSTALL_MASK, LC_ALL, PORTAGE_BUNZIP2_COMMAND, PORTAGE_COMPRESS, PORTAGE_COMPRESS_FLAGS, PORTAGE_RSYNC_EXTRA_OPTS, USE_PYTHON


Last edited by somethin on Sat Feb 27, 2016 3:31 pm; edited 1 time in total
Back to top
View user's profile Send private message
khayyam
Watchman
Watchman


Joined: 07 Jun 2012
Posts: 6227
Location: Room 101

PostPosted: Tue Jan 19, 2016 2:49 pm    Post subject: Reply with quote

somethin ...

You should have the following:

Code:
# egrep -v '(^#|^$)' /etc/conf.d/hostname
hostname="myhostname"
# zgrep HOSTNAME /proc/config.gz
CONFIG_DEFAULT_HOSTNAME="(none)"
# rc-status --all | grep hostname | tr -s ' '
 hostname [ started ]
# hostname
myhostname

HTH & best ... khay
Back to top
View user's profile Send private message
somethin
n00b
n00b


Joined: 19 Jan 2016
Posts: 37

PostPosted: Tue Jan 19, 2016 4:37 pm    Post subject: Reply with quote

Code:

# egrep -v '(^#|^$)' /etc/conf.d/hostname
hostname="righthost"
# zgrep HOSTNAME /proc/config.gz
gzip: /proc/config.gz: No such file or directory
# rc-status --all | grep hostname | tr -s ' '
 hostname [ started ]
# hostname
wronghost

Code:

# cat /usr/src/linux/.config | grep CONFIG_DEFAULT_HOSTNAME
CONFIG_DEFAULT_HOSTNAME="(none)"
Back to top
View user's profile Send private message
Fitzcarraldo
Advocate
Advocate


Joined: 30 Aug 2008
Posts: 2034
Location: United Kingdom

PostPosted: Tue Jan 19, 2016 4:41 pm    Post subject: Reply with quote

Are you using NetworkManager, by any chance? If you are, specify the hostname in the file /etc/NetworkManager/NetworkManager.conf as shown below. Obviously change 'dhclient' to dhcpcd' if you merged NetworkManager to use dhcpcd instead of dhclient.

Code:
[main]
plugins=keyfile
dhcp=dhclient

[keyfile]
hostname=righthost

Also, please post the contents of /etc/hosts and /etc/conf.d/hostname.

You mentioned /etc/dhcp/dhclient.conf. I have the following in mine:

Code:
send host-name "righthost";
supersede host-name "righthost";

_________________
Clevo W230SS: amd64, VIDEO_CARDS="intel modesetting nvidia".
Compal NBLB2: ~amd64, xf86-video-ati. Dual boot Win 7 Pro 64-bit.
OpenRC udev elogind & KDE on both.

Fitzcarraldo's blog
Back to top
View user's profile Send private message
somethin
n00b
n00b


Joined: 19 Jan 2016
Posts: 37

PostPosted: Tue Jan 19, 2016 5:24 pm    Post subject: Reply with quote

Adding
Code:

send host-name "righthost";
supersede host-name "righthost";

solved problem when using dhclient, but when using dhcpcd problem still exists. Adding
Code:

[main]
plugins=keyfile
dhcp=dhclient

[keyfile]
hostname=righthost

to /etc/NetworkManager/NetworkManager.conf didn't work.

Code:

# cat /etc/hosts
# /etc/hosts: Local Host Database
#
# This file describes a number of aliases-to-address mappings for the for
# local hosts that share this file.
#
# In the presence of the domain name service or NIS, this file may not be
# consulted at all; see /etc/host.conf for the resolution order.
#

# IPv4 and IPv6 localhost aliases
127.0.0.1       localhost
::1             localhost

#
# Imaginary network.
#10.0.0.2               myname
#10.0.0.3               myfriend
#
# According to RFC 1918, you can use the following IP networks for private
# nets which will never be connected to the Internet:
#
#       10.0.0.0        -   10.255.255.255
#       172.16.0.0      -   172.31.255.255
#       192.168.0.0     -   192.168.255.255
#
# In case you want to be able to connect directly to the Internet (i.e. not
# behind a NAT, ADSL router, etc...), you need real official assigned
# numbers.  Do not try to invent your own network numbers but instead get one
# from your network provider (if any) or from your regional registry (ARIN,
# APNIC, LACNIC, RIPE NCC, or AfriNIC.)
#

Code:

# cat /etc/conf.d/hostname
# Set to the hostname of this machine
hostname="righthost"
Back to top
View user's profile Send private message
Ant P.
Watchman
Watchman


Joined: 18 Apr 2009
Posts: 6920

PostPosted: Tue Jan 19, 2016 6:22 pm    Post subject: Reply with quote

What's in your /etc/hosts?
Back to top
View user's profile Send private message
somethin
n00b
n00b


Joined: 19 Jan 2016
Posts: 37

PostPosted: Tue Jan 19, 2016 6:33 pm    Post subject: Reply with quote

Code:

# /etc/hosts: Local Host Database
#
# This file describes a number of aliases-to-address mappings for the for
# local hosts that share this file.
#
# In the presence of the domain name service or NIS, this file may not be
# consulted at all; see /etc/host.conf for the resolution order.
#

# IPv4 and IPv6 localhost aliases
127.0.0.1       localhost
::1             localhost

#
# Imaginary network.
#10.0.0.2               myname
#10.0.0.3               myfriend
#
# According to RFC 1918, you can use the following IP networks for private
# nets which will never be connected to the Internet:
#
#       10.0.0.0        -   10.255.255.255
#       172.16.0.0      -   172.31.255.255
#       192.168.0.0     -   192.168.255.255
#
# In case you want to be able to connect directly to the Internet (i.e. not
# behind a NAT, ADSL router, etc...), you need real official assigned
# numbers.  Do not try to invent your own network numbers but instead get one
# from your network provider (if any) or from your regional registry (ARIN,
# APNIC, LACNIC, RIPE NCC, or AfriNIC.)
#
Back to top
View user's profile Send private message
Ant P.
Watchman
Watchman


Joined: 18 Apr 2009
Posts: 6920

PostPosted: Tue Jan 19, 2016 7:40 pm    Post subject: Reply with quote

Well, only one more question: what does your DNS server say your hostname is?
Back to top
View user's profile Send private message
somethin
n00b
n00b


Joined: 19 Jan 2016
Posts: 37

PostPosted: Tue Jan 19, 2016 7:42 pm    Post subject: Reply with quote

How can I check that ?
Back to top
View user's profile Send private message
Ant P.
Watchman
Watchman


Joined: 18 Apr 2009
Posts: 6920

PostPosted: Tue Jan 19, 2016 7:58 pm    Post subject: Reply with quote

`host <your-ip>` or `busybox nslookup <ip>` should show it.
Back to top
View user's profile Send private message
somethin
n00b
n00b


Joined: 19 Jan 2016
Posts: 37

PostPosted: Tue Jan 19, 2016 8:21 pm    Post subject: Reply with quote

Code:

# busybox nslookup 192.168.1.x
Server:    192.168.1.1
Address 1: 192.168.1.1 something

Name:      192.168.1.x
Address 1: 192.168.1.x wronghost
Back to top
View user's profile Send private message
Ant P.
Watchman
Watchman


Joined: 18 Apr 2009
Posts: 6920

PostPosted: Tue Jan 19, 2016 10:33 pm    Post subject: Reply with quote

It's getting it from the DNS server. Simple solution: just define the right one after localhost in /etc/hosts.

(Or fix the DNS server, if you have access to do so)
Back to top
View user's profile Send private message
Fitzcarraldo
Advocate
Advocate


Joined: 30 Aug 2008
Posts: 2034
Location: United Kingdom

PostPosted: Wed Jan 20, 2016 4:26 am    Post subject: Reply with quote

Gentoo Handbook wrote:
The hosts file

The /etc/hosts file is a small table the system uses to make immediate translations between hostnames and IP addresses. This file should at least contain one line:

127.0.0.1 localhost

All other lines should be set under that line using the following syntax:

<ip address> <fully qualified hostname> <aliases>

For instance, if you want to assign the host name gentoobox to the eth0 interface address (for instance, 192.168.0.2):

192.168.0.2 gentoobox

If you use a domain name for your network (such as boxes, but it can also be a real reserved domain name like company.com), you should set it like so:

192.168.0.2 gentoobox.boxes gentoobox


The /etc/hosts file in my Clevo W230SS laptop looks like the following and works with all the networks I use (DHCP and static addressing) with NetworkManager (IP addresses for static-address networks specified via NetworkManager GUI front-end, which, in my case, is plasma-nm, and present in /etc/NetworkManager/system-connections/* files):

Code:
127.0.0.1 righthost localhost
::1 righthost localhost

_________________
Clevo W230SS: amd64, VIDEO_CARDS="intel modesetting nvidia".
Compal NBLB2: ~amd64, xf86-video-ati. Dual boot Win 7 Pro 64-bit.
OpenRC udev elogind & KDE on both.

Fitzcarraldo's blog
Back to top
View user's profile Send private message
somethin
n00b
n00b


Joined: 19 Jan 2016
Posts: 37

PostPosted: Wed Jan 20, 2016 8:00 am    Post subject: Reply with quote

After adding righthost after localhost in /etc/hosts, 'hostname' shows righthost, but 'busybox nslookup 192.168.1.x' still shows wronghost. Adding '192.168.1.x righthost' in /etc/hosts solved that problem.
But, if it's because of dns, how can I update dns hostname ?(because removing '192.168.1.x righthost' from /etc/hosts shows wronghost when runnning 'busybox nslookup 192.168.1.x' again)
Back to top
View user's profile Send private message
Syl20
l33t
l33t


Joined: 04 Aug 2005
Posts: 619
Location: France

PostPosted: Mon Jan 25, 2016 7:18 pm    Post subject: Reply with quote

What is 192.168.1.1 ? As your DNS server resides here, you need to watch how it delivers the naming service, and find its configuration files.
Back to top
View user's profile Send private message
somethin
n00b
n00b


Joined: 19 Jan 2016
Posts: 37

PostPosted: Mon Jan 25, 2016 8:13 pm    Post subject: Reply with quote

192.168.1.1 is my router and after rebooting it (with "send host-name = gethostname();" in /etc/dhcp/dhclient.conf when using dhclient) "busybox nslookup 192.168.1.x" shows right hostname.
Thanks a lot everyone for help.
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Other Things Gentoo All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum